<?php
error_reporting(E_ALL ^ E_NOTICE);
//超时设置
if($public_r['php_outtime'])
{
	@set_time_limit($public_r['php_outtime']);
}

//页面编码
if($phome_headercharset==1)
{
	if($phome_ecms_charver=='gb2312'||$phome_ecms_charver=='big5'||$phome_ecms_charver=='utf-8')
	{
		@header('Content-Type: text/html; charset='.$phome_ecms_charver);
	}
}

//禁止IP
eCheckAccessIp(0);

//分页
function postpage($num,$line,$page_line,$start,$page,$form){
	global $fun_r;
	$pagetotal=$line*$page_line;//所要显示的总条数
	$total=ceil(($num-$start)/$line);//取得总页数
	$total_start=ceil($num/$pagetotal);//取得总偏移数
	$returnstr=$fun_r[totalrecord]."&nbsp;".$num."&nbsp;".$fun_r[totalrecorde]."&nbsp;&nbsp;";
	if($start!=0)
	{
		$old_start=$start-$pagetotal;
		$returnstr.="&nbsp;&nbsp;<a href='#ecms' onclick='javascript:GotoPostPage(0,$old_start);' title='UP".$page_line."Pages'><font face=webdings>7</font></a>";
	}
	$pagestart=$start/$pagetotal*$page_line;//取得当前页数
	for($i=0;$i<$total&&$i<$page_line;$i++)
	{
		if($page==$i)
		{
			$is_1="<b>[";$is_2="]</b>";
		}
		else
		{
			$is_1="<a href='#ecms' onclick='javascript:GotoPostPage($i,$start);'>";
			$is_2="</a>";
		}
		$pagenum=$pagestart+$i+1;
		$returnstr.="&nbsp;&nbsp;".$is_1.$pagenum.$is_2;
	}
	if($total_start!=($start/$pagetotal+1)&&$num!=0)
	{
		$new_start=$start+$pagetotal;
		$returnstr.="&nbsp;&nbsp;<a href='#ecms' onclick='javascript:GotoPostPage(0,$new_start);' title='Next".$page_line."Pages'><font face=webdings>8</font></a>";
	}
	$returnstr.="<script>
	function GotoPostPage(page,start){
		".$form.".page.value=page;
		".$form.".start.value=start;
		".$form.".submit();
	}
	</script>";
	return $returnstr;
}

//取得模型表名
function GetModTable($mid){
	global $empire,$dbtbpre;
	$r=$empire->fetch1("select tid,tbname from {$dbtbpre}enewsmod where mid='$mid'");
	return $r;
}

//建立专题目录
function CreateZtPath($ztpath){
	$createpath='../../'.$ztpath;
    $mk=DoMkdir($createpath);
}

//建立栏目目录
function CreateClassPath($classpath){
	$createpath='../../'.$classpath;
	$mk=DoMkdir($createpath);
	$createfilepath="../../d/file/".$classpath;//建立附件目录
    $mk1=DoMkdir($createfilepath);
}

//删除栏目缓存文件
function DelListEnews(){
	$file="../data/fc/ListEnews.php";
	DelFiletext($file);
	$file1="../data/fc/ListClass0.php";
	DelFiletext($file1);
	$file2="../data/fc/ListClass1.php";
	DelFiletext($file2);
}

//替换php代码
function RepPhpAspJspcode($string){
	global $public_r;
	if(!$public_r[candocode]){
		//$string=str_replace("<?xml","[!--ecms.xml--]",$string);
		$string=str_replace("<?","&lt;?",$string);
		$string=str_replace("<%","&lt;%",$string);
		//$string=str_replace("[!--ecms.xml--]","<?xml",$string);
	}
	return $string;
}

//替换php代码
function RepPhpAspJspcodeText($string){
	//$string=str_replace("<?xml","[!--ecms.xml--]",$string);
	$string=str_replace("<?","&lt;?",$string);
	$string=str_replace("<%","&lt;%",$string);
	//$string=str_replace("[!--ecms.xml--]","<?xml",$string);
	$string=str_replace("<!--code.start-->","&lt;!--code.start--&gt;",$string);
	$string=str_replace("<!--code.end-->","&lt;!--code.end--&gt;",$string);
	return $string;
}

//标签替换
function NewsBq($classid,$indextext,$enews=0,$doing=0){
	global $empire,$public_r,$class_r,$class_zr,$fun_r,$navinfor,$addgethtmlpath,$dbtbpre;
	$indextext=stripSlashes($indextext);
	if($enews==0)//生成大栏目文件
	{
		if(strstr($public_r['nreclass'],','.$classid.',')||$class_r[$classid][wburl])//不生成栏目
		{
			return '';
		}
		$GLOBALS['navclassid']=$classid;
		$url="<!--empire.url-->".ReturnClassLink($classid)."<!--empire.url-->";//栏目导航
		if($doing)//修改栏目时
		{
			$cr=$empire->fetch1("select classpath,classtype,classname from {$dbtbpre}enewsclass where classid='$classid'");
			$class_r[$classid][classpath]=$cr[classpath];
			$class_r[$classid][classtype]=$cr[classtype];
			$class_r[$classid][classname]=$cr[classname];
	    }
		$pagetitle=$class_r[$classid][classname];//标题
		if($public_r['openclasspv'])//开启点击
		{
			$onclick="<script src=".$public_r[newsurl]."e/public/onclick?enews=doclass&classid=$classid></script>";
		}
		$truefile="../../".ReturnSaveClassPath($classid,1);
		$file="../data/tmp/class".$classid.".php";
	}
	elseif($enews==1)//生成首页文件
	{
		$pagetitle=$public_r[sitename];
		$url="<!--empire.url--><a href=\"".$public_r[newsurl]."\">".$fun_r['index']."</a><!--empire.url-->";//栏目导航
		$onclick="";
		$truefile="../../".ReturnSaveIndexFile();
		$file="../data/tmp/index.php";
	}
	elseif($enews==2)//页面模板标签
	{
		$onclick="";
		$truefile="";
		$file=$addgethtmlpath."../data/tmp/temp".$classid.".php";
    }
	elseif($enews==3)//专题
	{
		$GLOBALS['navclassid']=$classid;
		$url="<!--empire.url-->".ReturnZtLink($classid)."<!--empire.url-->";//栏目导航
		if($doing)//修改专题时
		{
			$cr=$empire->fetch1("select ztpath,zttype,ztname from {$dbtbpre}enewszt where ztid='$classid'");
			$class_zr[$classid][ztpath]=$cr[ztpath];
			$class_zr[$classid][zttype]=$cr[zttype];
			$class_zr[$classid][ztname]=$cr[ztname];
	    }
		$pagetitle=$class_zr[$classid][ztname];
		if($public_r['openclasspv'])
		{
			$onclick="<script src=".$public_r[newsurl]."e/public/onclick?enews=dozt&ztid=$ztid></script>";
		}
		$truefile="../../".ReturnSaveZtPath($classid,1);
		$file="../data/tmp/zt".$classid.".php";
	}
	$indextext=ReplaceTempvar($indextext);//替换全局模板变量
	if($classid&&$enews==0)//栏目id
	{
		$indextext=RepClassPageVar($indextext,$classid,$r,0);
		$indextext=str_replace("[!--self.classid--]",$classid,$indextext);
		$indextext=str_replace("[!--news.url--]",$public_r['newsurl'],$indextext);
		$indextext=str_replace("[!--pagetitle--]",$pagetitle,$indextext);//替换标题
	}
	elseif($classid&&$enews==3)//专题id
	{
		$indextext=RepClassPageVar($indextext,$classid,$r,1);
		$indextext=str_replace("[!--self.classid--]",$classid,$indextext);
		$indextext=str_replace("[!--news.url--]",$public_r['newsurl'],$indextext);
		$indextext=str_replace("[!--pagetitle--]",$pagetitle,$indextext);//替换标题
	}
	elseif($enews==1)//首页
	{
		$indextext=str_replace("[!--self.classid--]",0,$indextext);
		$indextext=str_replace("[!--news.url--]",$public_r['newsurl'],$indextext);
		$indextext=str_replace("[!--pagetitle--]",$pagetitle,$indextext);//替换标题
	}
	//替换导航
	if($url)
	{
		$indextext=str_replace("[!--newsnav--]",$url,$indextext);
	}
	//替换标签
	$indextext=DoRepEcmsLoopBq($indextext);
	$indextext=RepBq($indextext);
	//写文件
	WriteFiletext($file,AddCheckViewTempCode().$indextext);
	//读取文件内容
    @ob_start();
	@include($file);
	$string=@ob_get_contents();
	@ob_end_clean();
	if($enews==0||$enews==1||$enews==3){
		$string=str_replace("[!--page.stats--]",$onclick,$string);
	}
	//解析代码
	$string=RepExeCode($string);
	if($enews<>2){
		WriteFiletext($truefile,$string);
	}
	//WriteFiletext($file,"");
	return $string;
}

//加模板验证代码
function AddCheckViewTempCode(){
	$code="<?php
if(!defined('InEmpireCMS'))
{
	exit();
}
?>";
	return $code;
}

//解析代码
function RepExeCode($string){
	global $public_r;
	if($public_r[candocode]){
		$string=str_replace("<!--code.start-->","<",$string);
		$string=str_replace("<!--code.end-->",">",$string);
    }
	return $string;
}

function ClearRepDoECode($string){
	$string=str_replace("<!--code.start-->","&lt;!--code.start--&gt;",$string);
	$string=str_replace("<!--code.end-->","&lt;!--code.end--&gt;",$string);
	return $string;
}

//重命名列表文件
function RenameListfile($classid,$lencord,$num,$type,$newtype,$classpath){
	$page=ceil($num/$lencord);
	for($j=1;$j<=$page;$j++){
		if($j==1){
			$listfile="../../".$classpath."/index";
		}
		else{
			$listfile="../../".$classpath."/index_".$j;
		}
		@rename($listfile.$type,$listfile.$newtype);
	}
}

//取得模型ID
function GetListtempMid($tempid){
	global $empire;
	$r=$empire->fetch1("select modid from ".GetTemptb("enewslisttemp")." where tempid='$tempid'");
	return $r[modid];
}

//取得列表模板
function GetListTemp($tempid){
	global $empire;
	$r=$empire->fetch1("select temptext,subnews,listvar,rownum,showdate,modid,subtitle from ".GetTemptb("enewslisttemp")." where tempid='$tempid'");
	$r[temptext]=NewsBq("list".$tempid,$r[temptext],2,0);
	return $r;
}

//取得封面模板
function GetClassTemp($tempid){
	global $empire;
	$r=$empire->fetch1("select temptext from ".GetTemptb("enewsclasstemp")." where tempid='$tempid'");
	return $r['temptext'];
}

//取得首页模板
function GetIndextemp(){
	global $empire;
	$r=$empire->fetch1("select indextemp from ".GetTemptb("enewspubtemp")." limit 1");
	return $r['indextemp'];
}

//刷新首页
function ReIndex(){
	$indextemp=GetIndextemp();//取得模板
	NewsBq($classid,$indextemp,1,0);
	insert_dolog("");//操作日志
	printerror("ReIndexSuccess","history.go(-1)");
}

//无信息的信息列表
function NotinfoListHtml($path,$list_r){
	global $fun_r;
	$word=$fun_r['HaveNotListInfo'];
	$pagetext=$list_r[0].$word.$list_r[2];
	$pagetext=str_replace("[!--show.page--]","",$pagetext);
	$pagetext=str_replace("[!--show.listpage--]","",$pagetext);
	$pagetext=str_replace("[!--list.pageno--]","",$pagetext);
	WriteFiletext($path,$pagetext);
}

//生成信息列表
function ListHtml($classid,$field,$enews=0,$userlistr=""){
	global $empire,$public_r,$class_r,$class_zr,$fun_r,$addgethtmlpath,$dbtbpre;
	//不生成栏目
	if(($enews==0||$enews==3)&&(strstr($public_r['nreclass'],','.$classid.',')||$class_r[$classid][wburl]))
	{
		return '';
	}
	$GLOBALS['navclassid']=$classid;
	$doclass="index";
	if($enews==0)//子栏目列表
	{
		$pagetitle=$class_r[$classid][classname];//标题
		$repclassvar=0;
		$haveclass=0;
		//排序
		if(empty($class_r[$classid][reorderf]))
		{
			$addorder=",newstime desc";
	    }
		else
		{
			$addorder=",".$class_r[$classid][reorderf]." ".$class_r[$classid][reorder];
	    }
		$url="<!--empire.url-->".ReturnClassLink($classid)."<!--empire.url-->";
		if($class_r[$classid][maxnum])//总记录数
		{
			$limit=" limit ".$class_r[$classid][maxnum];
			$limitnum=$class_r[$classid][maxnum];
		}
		$query="select * from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where classid='$classid' and checked=1 order by istop desc".$addorder.",id desc".$limit;
		$totalquery="select count(*) as total from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where classid='$classid' and checked=1";//统计
		$doclasspath=ReturnSaveClassPath($classid,0);
		$dopath=$addgethtmlpath."../../".$doclasspath."/";
		if(empty($class_r[$classid][classurl]))
		{
			$dolink=$public_r[newsurl].$doclasspath."/";
		}
		else
		{
			$dolink=$class_r[$classid][classurl]."/";
		}
		$dotype=$class_r[$classid][classtype];
		$classname=$class_r[$classid][classname];
		$lencord=$class_r[$classid][lencord];//记录数
		if($public_r['openclasspv'])
		{
			$onclick="<script src=".$public_r[newsurl]."e/public/onclick?enews=doclass&classid=$classid></script>";
		}
		//模板
		$templateid=$class_r[$classid][templateid];
		$listtempid=$class_r[$classid][listtempid];
	}
	elseif($enews==1)//专题列表
	{
		$pagetitle=$class_zr[$classid][ztname];//标题
		$repclassvar=1;
		$haveclass=1;
		if(!$class_zr[$classid][islist])//非列表式
		{
			$r=$empire->fetch1("select classtempid from {$dbtbpre}enewszt where ztid='$classid'");
			NewsBq($classid,GetClassTemp($r['classtempid']),3,0);
			return "";
		}
		//排序
		if(empty($class_zr[$classid][reorderf]))
		{
			$addorder=",newstime desc";
	    }
		else
		{
			$addorder=",".$class_zr[$classid][reorderf]." ".$class_zr[$classid][reorder];
	    }
		$url="<!--empire.url-->".ReturnZtLink($classid)."<!--empire.url-->";
		if($class_zr[$classid][maxnum])
		{
			$limit=" limit ".$class_zr[$classid][maxnum];
			$limitnum=$class_zr[$classid][maxnum];
		}
		$query="select * from {$dbtbpre}ecms_".$class_zr[$classid][tbname]." where ztid like '%|".$classid."|%' and checked=1 order by istop desc".$addorder.",id desc".$limit;
		$totalquery="select count(*) as total from {$dbtbpre}ecms_".$class_zr[$classid][tbname]." where ztid like '%|".$classid."|%' and checked=1";//统计
		$doclasspath=ReturnSaveZtPath($classid,0);
		$dopath=$addgethtmlpath."../../".$doclasspath."/";
		if(empty($class_zr[$classid][zturl]))
		{
			$dolink=$public_r[newsurl].$doclasspath."/";
		}
		else
		{
			$dolink=$class_zr[$classid][zturl]."/";
		}
		$dotype=$class_zr[$classid][zttype];
		$classname=$class_zr[$classid][ztname];
		$lencord=$class_zr[$classid][ztnum];//记录数
		if($public_r['openclasspv'])
		{
			$onclick="<script src=".$public_r[newsurl]."e/public/onclick?enews=dozt&ztid=$classid></script>";
		}
		//模板
		$templateid=$class_zr[$classid][templateid];
		$listtempid=$class_zr[$classid][listtempid];
	}
	elseif($enews==3)//大栏目列表
	{
		$pagetitle=$class_r[$classid][classname];//标题
		$repclassvar=0;
		$haveclass=1;
		//排序
		if(empty($class_r[$classid][reorderf]))
		{
			$addorder=",newstime desc";
	    }
		else
		{
			$addorder=",".$class_r[$classid][reorderf]." ".$class_r[$classid][reorder];
	    }
		$url="<!--empire.url-->".ReturnClassLink($classid)."<!--empire.url-->";
		$whereclass=ReturnClass($class_r[$classid][sonclass]);
		if($class_r[$classid][maxnum])
		{
			$limit=" limit ".$class_r[$classid][maxnum];
			$limitnum=$class_r[$classid][maxnum];
		}
		$query="select * from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where (".$whereclass.") and checked=1 order by istop desc".$addorder.",id desc".$limit;
		$totalquery="select count(*) as total from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where (".$whereclass.") and checked=1";//统计
		$doclasspath=ReturnSaveClassPath($classid,0);
		$dopath=$addgethtmlpath."../../".$doclasspath."/";
		if(empty($class_r[$classid][classurl]))
		{
			$dolink=$public_r[newsurl].$doclasspath."/";
		}
		else
		{
			$dolink=$class_r[$classid][classurl]."/";
		}
		$dotype=$class_r[$classid][classtype];
		$classname=$class_r[$classid][classname];
		$lencord=$class_r[$classid][lencord];//记录数
		if($public_r['openclasspv'])
		{
			$onclick="<script src=".$public_r[newsurl]."e/public/onclick?enews=doclass&classid=$classid></script>";
		}
		//模板
		$listtempid=$class_r[$classid][listtempid];
	}
	elseif($enews==4)//按sql语句生成列表
	{
		$userlistr['listsql']=RepSqlTbpre($userlistr['listsql']);
		$userlistr['totalsql']=RepSqlTbpre($userlistr['totalsql']);
		$pagetitle=$userlistr['pagetitle'];//标题
		$repclassvar=2;
		$haveclass=1;
		if($userlistr['maxnum'])//最大查询数
		{
			$limit=" limit ".$userlistr['maxnum'];
			$limitnum=$userlistr['maxnum'];
		}
		$query=stripSlashes($userlistr['listsql']).$limit;
		//统计
		$totalquery=stripSlashes($userlistr['totalsql']);
		$dopath=$userlistr['addpath'].$userlistr['filepath'];
		$dolink=$public_r[newsurl].str_replace($userlistr['addpath']."../../","",$dopath);
		$dotype=$userlistr['filetype'];
		$classname=$userlistr['pagetitle'];
		$lencord=$userlistr['lencord'];//记录数
		$onclick="";
		//模板
		$listtempid=$userlistr['listtempid'];
	}
	if(empty($lencord))
	{
		$lencord=25;
	}
	//列表模板
	$listtemp_r=GetListTemp($listtempid);
    $listtemp=$listtemp_r[temptext];
	$subnews=$listtemp_r[subnews];
	$subtitle=$listtemp_r[subtitle];
	$listvar=$listtemp_r[listvar];
	$rownum=$listtemp_r[rownum];
	$formatdate=$listtemp_r[showdate];
	if(empty($rownum))
	{
		$rownum=1;
	}
	//专题
	if($enews==1||$enews==3||$enews==4)
	{
		$ret_r=ReturnAddF($r,$listtemp_r[modid],$userid,$username,2,2,0);
		$field=$ret_r;
	}
	//替换模板变量
	$listtemp=ReplaceSvars($listtemp,$classid,$pagetitle,$url,$enews);
	$listtemp=RepClassPageVar($listtemp,$classid,$userlistr,$repclassvar);//栏目变量
	$listtemp=str_replace("[!--news.url--]",$public_r[newsurl],$listtemp);
	$listtemp=str_replace("[!--self.classid--]",$classid,$listtemp);
	$listtemp=str_replace("[!--page.stats--]",$onclick,$listtemp);
	//分页列表函数
	if(!empty($public_r['listpagefun'])||!empty($public_r['listpagelistfun']))
	{
		if(strstr($listtemp,"[!--show.page--]"))//下拉式
		{
			$thefun=$public_r['listpagefun'];
			$bereplistpage="[!--show.page--]";
		}
		else//列表式
		{
			$thefun=$public_r['listpagelistfun'];
			$bereplistpage="[!--show.listpage--]";
		}
	}
	else
	{
		$thefun="sys_ShowListPage";
		$bereplistpage="[!--show.page--]";
	}
	$no=1;
	$ok=0;
	$changerow=1;
	$num=$empire->gettotal($totalquery);
	//最大数
	if($limitnum&&$limitnum<$num)
	{
		$num=$limitnum;
	}
	$page=ceil($num/$lencord);
	//取得列表模板
	$list_exp="[!--empirenews.listtemp--]";
	$list_r=explode($list_exp,$listtemp);
	//无信息
	if(empty($num))
	{
		$noinfopath=$dopath."index".$dotype;
		NotinfoListHtml($noinfopath,$list_r);
		return "";
	}
	$sql=$empire->query($query);
	$listtext=$list_r[1];
	while($k=$empire->fetch($sql))
	{
		//替换列表变量
		$repvar=ReplaceListVars($no,$listvar,$subnews,$subtitle,$formatdate,$url,$haveclass,$k,$field);
		$listtext=str_replace("<!--list.var".$changerow."-->",$repvar,$listtext);
		$changerow+=1;
		//超过行数
		if($changerow>$rownum)
		{
			$changerow=1;
			$string.=$listtext;
			$listtext=$list_r[1];
		}
		if($no%$lencord==0||($num%$lencord<>0&&$num==$no))
		{
			$ok+=1;
			$pagenum=ceil($no/$lencord);
			//首页
			if($pagenum==1)
			{
				$path=$dopath."index".$dotype;
			}
			else
			{
				$path=$dopath."index_".$ok.$dotype;
			}
			//取得分页参数
			$returnpager=$thefun($num,$pagenum,$dolink,$dotype,$page,$lencord,$ok,$myoptions);
			$showpage=$returnpager['showpage'];
			$myoptions=$returnpager['option'];
			$list1=str_replace($bereplistpage,$showpage,$list_r[0]);
			$list2=str_replace($bereplistpage,$showpage,$list_r[2]);
			//多余数据
			if($changerow<=$rownum&&$listtext<>$list_r[1])
			{
				$string.=$listtext;
			}
			$listtext=$list_r[1];
			$changerow=1;
			$string=$list1.$string.$list2;
			//替换分页数
			$string=str_replace("[!--list.pageno--]",$pagenum,$string);
			WriteFiletext($path,$string);
			$string="";
		}
		$no++;
	}
	$empire->free($sql);
}

//返回分页
function ReturnListpageStr($pagenum,$page,$lencord,$num,$pagelink,$options){
	global $public_r;
	$temp=$public_r['listpagetemp'];
	$temp=str_replace("[!--thispage--]",$pagenum,$temp);//页次
	$temp=str_replace("[!--pagenum--]",$page,$temp);//总页数
	$temp=str_replace("[!--lencord--]",$lencord,$temp);//每页显示条数
	$temp=str_replace("[!--num--]",$num,$temp);//总条数
	$temp=str_replace("[!--pagelink--]",$pagelink,$temp);//页面链接
	$temp=str_replace("[!--options--]",$options,$temp);//下拉分页
	return $temp;
}

//替换栏目页面变量
function RepClassPageVar($temp,$classid,$r,$ecms=0){
	global $empire,$dbtbpre,$class_r;
	if($ecms==2)
	{
		return $temp;
	}
	if($ecms!=1){
		$bclassid=$class_r[$classid]['bclassid'];
		$temp=str_replace('[!--bclass.id--]',$bclassid,$temp);
		$temp=str_replace('[!--bclass.name--]',$class_r[$bclassid]['classname'],$temp);
	}
	if(!(strstr($temp,'[!--class.intro--]')||strstr($temp,'[!--class.keywords--]')||strstr($temp,'[!--class.classimg--]'))){
		return $temp;
	}
	if($ecms==0)//栏目
	{
		$r=$empire->fetch1("select intro,classpagekey,classimg from {$dbtbpre}enewsclass where classid='$classid'");
	}
	elseif($ecms==1)//专题
	{
		$r=$empire->fetch1("select intro,ztpagekey as classpagekey,ztimg as classimg from {$dbtbpre}enewszt where ztid='$classid'");
	}
	$temp=str_replace("[!--class.intro--]",$r['intro'],$temp);
	$temp=str_replace("[!--class.keywords--]",$r['classpagekey'],$temp);
	$temp=str_replace("[!--class.classimg--]",$r['classimg'],$temp);
	return $temp;
}

//投稿生成html
function DoGetHtml($classid,$id){
	global $empire,$class_r,$public_r,$dbtbpre,$addgethtmlpath;
	$classid=intval($classid);
	$id=intval($id);
	$tbname=$class_r[$classid][tbname];
	//不存在
	if(!$id||!$classid||!$tbname)
	{
		echo"<script>self.location.href='".$public_r['newsurl']."';</script>";
		exit();
	}
	$r=$empire->fetch1("select * from {$dbtbpre}ecms_".$tbname." where id='$id'");
	if(!$r[id]||!$r['checked'])
	{
		echo"<script>self.location.href='".$public_r['newsurl']."';</script>";
		exit();
	}
	$titleurl=sys_ReturnBqAutoTitleLink($r);
	//已生成
	if(!empty($r[havehtml]))
	{
		return $titleurl;
	}
	//返回自定义字段
	$ret_r=ReturnAddF($r,$class_r[$classid][modid],$userid,$username,2,1,0);
	//生成html
	GetHtml($r,$ret_r);
	return $titleurl;
}

//生成内容文件
function GetHtml($add,$field){
	global $public_r,$class_r,$class_zr,$fun_r,$empire,$addgethtmlpath,$formattxt,$dbtbpre;
	//外部链接
	if($add['titleurl']||$add['checked']==0||strstr($public_r['nreinfo'],','.$add['classid'].','))
	{
		return "";
	}
	$iclasspath=ReturnSaveInfoPath($add[classid],$add[id]);
	$doclasspath=$addgethtmlpath.'../../'.$iclasspath;
	$createinfopath=$doclasspath;
	//建立日期目录
	$newspath="";
	if($add[newspath])
	{
		$createpath=$doclasspath.$add[newspath];
		if(!file_exists($createpath)){
			$r[newspath]=FormatPath($add[classid],$add[newspath],1);
		}
		$createinfopath.=$add[newspath].'/';
		$newspath=$add[newspath]."/";
	}
	//新建存放目录
	if($class_r[$add[classid]][filename]==3){
		$createinfopath.=ReturnInfoSPath($add['filename']);
		DoMkdir($createinfopath);
		$fn3=1;
	}
	//存放文本
	if(strstr($public_r['savetxtf'],",".$class_r[$add[classid]][tbname].".newstext,")){
		$add[newstext]=GetTxtFieldText($add[newstext]);
	}
	$GLOBALS['navclassid']=$add[classid];
	$GLOBALS['navnewsid']=$add[id];
	$GLOBALS['navinfor']=$add;
	//取得内容模板
	$newstemp_r=GetNewsTemp($add[newstempid]);
	//格式化内容
	if($formattxt==1){
		$add[newstext]=@sys_FormatNewstext($add[newstext]);
	}
	$newstemptext=$newstemp_r[temptext];
	$formatdate=$newstemp_r[showdate];
	$newstemptext=RepClassPageVar($newstemptext,$add['classid'],$r,0);//栏目变量
	//导航条
	$url="<!--empire.url-->".ReturnClassLink($add[classid])."<!--empire.url-->";
	//文件类型/权限
	if($add[groupid])
	{
		if(empty($add[newspath])){
			$include="";
	    }
		else{
			$pr=explode("/",$add[newspath]);
			for($i=0;$i<count($pr);$i++){
				$include.="../";
			}
		}
		if($fn3==1)
		{
			$include.="../";
		}
		$pr=explode("/",$iclasspath);
		$pcount=count($pr);
		for($i=0;$i<$pcount-1;$i++)
		{
			$include.="../";
		}
		$include1=$include;
		$include.="e/class/CheckLevel.php";
		$filetype=".php";
		$addlevel="<?php
		define('empirecms','wm_chief');
		\$check_tbname='".$class_r[$add[classid]][tbname]."';
		\$check_infoid=".$add[id].";
		\$check_classid=".$add[classid].";
		\$check_path=\"".$include1."\";
		@include(\"".$include."\");
		?>";
    }
	else
	{
		$filetype=$class_r[$add[classid]][filetype];
		$addlevel="";
	}
	//取得本目录链接
	$dolink="";
	if(empty($add[titleurl]))
	{
		if($class_r[$add[classid]][classurl])//域名
		{
			$dolink=$class_r[$add[classid]][classurl]."/".$newspath;
		}
		else
		{
			$dolink=$public_r[newsurl].$iclasspath.$newspath;
		}
	}
	//替换模板变量
	$newstemptext=ReplaceSvars($newstemptext,$add[classid],$add[title],$url,0);
	//相关信息
	if(strstr($newstemptext,"[!--other.link--]"))
	{
    	$keyboardtext=GetKeyboard($add[keyboard],$add[keyid],$add[classid],$add[id],$class_r[$add[classid]][link_num]);
	}
	if($public_r['openpagepv'])
	{
		$onclick="<script src='".$public_r[newsurl]."e/public/onclick?enews=donews&classid=$add[classid]&id=".$add[id]."'></script>";
	}
	$newstext=$add[newstext];
	if($newstext)
	{
		$newstext=ReplaceWord($newstext);//过滤字符
		if(!empty($add[dokey]))//替换关键字
		{
			$newstext=ReplaceKey($newstext);
		}
		if($public_r['opencopytext'])
		{
			$newstext=AddNotCopyRndStr($newstext);//随机复制字符
		}
	}
	$n_r=explode("[!--empirenews.page--]",$newstext);
	$thispagenum=count($n_r);
	$titleselect="";
	//取得分页
	if(!empty($public_r['textpagefun']))
	{
		$thefun=$public_r['textpagefun'];
	}
	else
	{
		$thefun="sys_ShowTextPage";
	}
	//$thistextpage_r=$thefun($thispagenum,$dolink,$add,$filetype,$n_r);
	//变量
	$nottobrf=',newstext,title,titlepic,newstime,befrom,writer,downpath,onlinepath,musicpath,booktexturl,';
	$fr=explode(",",$field['tempvar']);
	//下拉式分页
	if(strstr($newstemptext,"[!--title.select--]"))
	{
		$dotitleselect=sys_ShowTextPageSelect($thispagenum,$dolink,$add,$filetype,$n_r);
	}
	for($j=1;$j<=$thispagenum;$j++)
	{
		$newstempstr=$newstemptext;//模板
		/*
		//上下页式
		if(strstr($newstemptext,"[!--nextpage.url--]"))
		{
			$shownextpageurl=sys_ShowTextNextPage($thispagenum,$dolink,$add,$filetype,$n_r,$j);
			$newstempstr=str_replace("[!--nextpage.url--]",$shownextpageurl,$newstempstr);
		}
		*/
		//下一页链接
		if($thispagenum==$j)
	    {
			$thisnextlink=$dolink.$add[filename].$filetype;
	    }
		else
	    {
			$thisj=$j+1;
			$thisnextlink=$dolink.$add[filename]."_".$thisj.$filetype;
		}
		$k=$j-1;
		if($j==1)
		{
			$file=$doclasspath.$newspath.$add[filename].$filetype;
			$title=$add[title];
		}
		else
		{
			$file=$doclasspath.$newspath.$add[filename]."_".$j.$filetype;
			$ti_r=explode("[/!--empirenews.page--]",$n_r[$k]);
			if(count($ti_r)>=2)
			{
				$n_r[$k]=$ti_r[1];
			}
			$title=$add['title'];
		}
		//取得当前页
		if($thispagenum==1)
		{
			$truepage="";
			$titleselect="";
		}
		else
		{
			$truepage=$thefun($thispagenum,$j,$dolink,$add,$filetype,'');
			$titleselect=str_replace("?".$j."\">","?".$j."\" selected>",$dotitleselect);
		}
		//变量
		for($i=1;$i<count($fr);$i++)
		{
			$f=$fr[$i];
			$value=$add[$f];
			if($f=="downpath")//下载地址
			{
				if(strstr($newstempstr,"[!--downpath--]"))
				{
					$value=ReturnDownSoftHtml($add);
				}
			}
			elseif($f=="onlinepath")//观看地址
			{
				if(strstr($newstempstr,"[!--onlinepath--]"))
				{
					$value=ReturnOnlinepathHtml($add);
				}
			}
			elseif($f=="morepic")//图片集
			{
				if(strstr($newstempstr,"[!--morepic--]"))
				{
					$value=ReturnMorepicpathHtml($add);
				}
			}
			elseif($f=="newstime")//时间
			{
				if(strstr($newstempstr,"[!--newstime--]"))
				{
					$value=format_datetime($value,$formatdate);
				}
			}
			elseif($f=="title")//标题
			{
				$value=$title;
			}		
			elseif($f=="befrom")//信息来源
			{
				if(strstr($newstempstr,"[!--befrom--]"))
				{
					$value=ReplaceBefrom($value);
				}
			}
			elseif($f=="writer")//作者
			{
				if(strstr($newstempstr,"[!--writer--]"))
				{
					$value=ReplaceWriter($value);
				}
			}
			elseif($f=="titlepic")//标题图片
			{
				if(empty($value))
				{$value=$public_r[newsurl]."e/data/images/notimg.gif";}
			}
			elseif($f=="newstext")//新闻内容
			{
				$value=$n_r[$k];
			}
			//正常字段
			if(!strstr($nottobrf,','.$f.','))
			{
				if(!strstr($field['tobrf'],','.$f.','))//加br
				{
					$value=nl2br($value);
				}
				if(strstr($field['dohtmlf'],','.$f.','))//去除html
				{
					$value=htmlspecialchars($value);
					$value=RepFieldtextNbsp($value);
				}
			}
			$newstempstr=str_replace("[!--".$f."--]",$value,$newstempstr);
		}
		//固定变量
		$newstempstr=str_replace("[!--id--]",$add[id],$newstempstr);
		$newstempstr=str_replace("[!--classid--]",$add[classid],$newstempstr);
		$newstempstr=str_replace("[!--self.classid--]",$add[classid],$newstempstr);
		$newstempstr=str_replace("[!--class.name--]",$class_r[$add[classid]][classname],$newstempstr);
		$newstempstr=str_replace("[!--onclick--]",$add[onclick],$newstempstr);
		$newstempstr=str_replace("[!--userfen--]",$add[userfen],$newstempstr);
		$newstempstr=str_replace("[!--username--]",$add[username],$newstempstr);
		//$newstempstr=str_replace("[!--ismember--]",$add[ismember],$newstempstr);
		//带链接的用户名
		if($add[ismember]==1&&$add[userid])
		{
			$newstempstr=str_replace("[!--linkusername--]","<a href='".$public_r[newsurl]."e/space?userid=".$add[userid]."' target=_blank>".$add[username]."</a>",$newstempstr);
		}
		else
		{
			$newstempstr=str_replace("[!--linkusername--]",$add[username],$newstempstr);
		}
		$newstempstr=str_replace("[!--userid--]",$add[userid],$newstempstr);
		$newstempstr=str_replace("[!--other.link--]",$keyboardtext,$newstempstr);
		$newstempstr=str_replace("[!--news.url--]",$public_r[newsurl],$newstempstr);
		$newstempstr=str_replace("[!--plnum--]",$add[plnum],$newstempstr);
		$newstempstr=str_replace("[!--totaldown--]",$add[totaldown],$newstempstr);
		$newstempstr=str_replace("[!--keyboard--]",$add[keyboard],$newstempstr);
		//导航
		$newstempstr=str_replace("[!--page.url--]",$truepage,$newstempstr);
		$newstempstr=str_replace("[!--title.select--]",$titleselect,$newstempstr);
		//加入收藏
    	$newstempstr=str_replace("[!--fava.url--]",$public_r[newsurl]."e/member/fava/add?classid=$add[classid]&id=".$add[id],$newstempstr);
		//链接
		$titleurl=sys_ReturnBqTitleLink($add);
		$newstempstr=str_replace("[!--titleurl--]",$titleurl,$newstempstr);
		$newstempstr=str_replace("[!--next.page--]",$thisnextlink,$newstempstr);
		//下一篇
		if(strstr($newstempstr,"[!--info.next--]"))
		{
			$next_r=$empire->fetch1("select titleurl,groupid,classid,newspath,filename,id,title from {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." where id>$add[id] and classid='$add[classid]' and checked=1 order by id limit 1");
			if(empty($next_r[id]))
			{
				$infonext=$fun_r['HaveNoNextLink'];
			}
			else
			{
				//链接
				$nexttitleurl=sys_ReturnBqTitleLink($next_r);
				$infonext="<a href='".$nexttitleurl."'>".$next_r[title]."</a>";
			}
			$newstempstr=str_replace("[!--info.next--]",$infonext,$newstempstr);
		}
		//上一篇
		if(strstr($newstempstr,"[!--info.pre--]"))
		{
			$next_r=$empire->fetch1("select titleurl,groupid,classid,newspath,filename,id,title from {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." where id<$add[id] and classid='$add[classid]' and checked=1 order by id desc limit 1");
			if(empty($next_r[id]))
			{
				$infonext=$fun_r['HaveNoNextLink'];
			}
			else
			{
				//链接
				$nexttitleurl=sys_ReturnBqTitleLink($next_r);
				$infonext="<a href='".$nexttitleurl."'>".$next_r[title]."</a>";
			}
			$newstempstr=str_replace("[!--info.pre--]",$infonext,$newstempstr);
		}
		//投票
		if(strstr($newstempstr,"[!--info.vote--]"))
		{
			$myvotetext=sys_GetInfoVote($add[classid],$add[id]);
			$newstempstr=str_replace("[!--info.vote--]",$myvotetext,$newstempstr);
		}
		//评分
		if(strstr($newstempstr,"[!--pinfopfen--]"))
		{
			$pinfopfen=$add[infopfennum]?round($add[infopfen]/$add[infopfennum]):0;
			$newstempstr=str_replace("[!--pinfopfen--]",$pinfopfen,$newstempstr);
			$newstempstr=str_replace("[!--infopfennum--]",$add[infopfennum],$newstempstr);
		}
		//关键字
		$newstempstr=str_replace("[!--keyboard--]",$add[keyboard],$newstempstr);
		//写文件
		$string=$addlevel.$newstempstr;
		$string=str_replace("[!--page.stats--]",$onclick,$string);
		WriteFiletext($file,$string);
	}
	//设为已生成
	if(empty($add['havehtml']))
	{
		$usql=$empire->query("update {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." set havehtml=1 where id='$add[id]' limit 1");
	}
}

//返回下载地址html代码
function ReturnDownSoftHtml($add){
	global $class_r,$public_r,$fun_r,$level_r;
	if(empty($add[downpath]))
	{
		return "";
	}
	//每行显示条数
	$down_num=$class_r[$add[classid]][down_num];
	if(empty($down_num))
	{
		$down_num=$public_r[down_num];
	}
	if(empty($down_num))
	{
		$down_num=1;
	}
	//组合地址
	$all_downpath="";
	$path_r=explode("\r\n",$add[downpath]);
	$count=count($path_r);
    for($pj=0;$pj<$count;$pj++)
    {
		$p=$pj+1;
        if($p%$down_num==0)
        {
			$ok="<br>";
		}
        else
        {
			$ok="";
		}
		//相同
		if($count==$p)
		{
			$ok="";
		}
		if($pj%$down_num==0||$pj==0)
        {
			$nbsp="";
		}
        else
        {
			$nbsp="&nbsp;&nbsp;";
		}
	    $showdown_r=explode("::::::",$path_r[$pj]);
	    if(count($showdown_r)<2)
		{
			$showdown_r[0]=$fun_r['DownPath'].$p;
		}
		//模板
		$downsofttemp=RepDownOnlinePathTemp($add,$public_r[downsofttemp],$pj,$showdown_r,0);
        $all_downpath.=$nbsp.stripSlashes($downsofttemp).$ok;
    }
	$value=$all_downpath;
	return $value;
}

//替换下载在线地址模板
function RepDownOnlinePathTemp($add,$downsofttemp,$pj,$showdown_r,$ecms){
	global $public_r,$level_r,$fun_r;
	if($ecms==0)//下载
	{
		$downurl=$public_r[newsurl]."e/DownSys/DownSoft?classid=$add[classid]&id=$add[id]&pathid=$pj";
	}
	else//在线
	{
		$downurl=$public_r[newsurl]."e/DownSys/play?classid=$add[classid]&id=$add[id]&pathid=$pj";
	}
	$downsofttemp=str_replace("[!--down.url--]",$downurl,$downsofttemp);
	$downsofttemp=str_replace("[!--down.name--]",$showdown_r[0],$downsofttemp);
	$downsofttemp=str_replace("[!--pathid--]",$pj,$downsofttemp);
	$downsofttemp=str_replace("[!--classid--]",$add[classid],$downsofttemp);
	$downsofttemp=str_replace("[!--id--]",$add[id],$downsofttemp);
	$downsofttemp=str_replace("[!--fen--]",$showdown_r[3],$downsofttemp);
	$group=$showdown_r[2]?$level_r[$showdown_r[2]][groupname]:$fun_r['hguest'];
	$downsofttemp=str_replace("[!--group--]",$group,$downsofttemp);
	if(strstr($downsofttemp,'[!--true.down.url--]'))
	{
		$durl=stripSlashes($showdown_r[1]);
		$durlr=ReturnDownQzPath($durl,$showdown_r[4]);
		$durl=$durlr['repath'];
		$downsofttemp=str_replace("[!--true.down.url--]",$durl,$downsofttemp);
	}
	return $downsofttemp;
}

//返回在线地址html代码
function ReturnOnlinepathHtml($add){
	global $class_r,$public_r,$fun_r,$level_r;
	if(empty($add[onlinepath]))
	{
		return "";
	}
	//每行显示条数
	$down_num=$class_r[$add[classid]][online_num];
	if(empty($down_num))
	{
		$down_num=$public_r[online_num];
	}
	if(empty($down_num))
	{
		$down_num=1;
	}
	$all_downpath="";
	$path_r=explode("\r\n",$add[onlinepath]);
	$count=count($path_r);
    for($pj=0;$pj<$count;$pj++)
    {
		$p=$pj+1;
        if($p%$down_num==0)
        {
			$ok="<br>";
		}
        else
        {
			$ok="";
		}
		//相同
		if($count==$p)
		{
			$ok="";
		}
		if($pj%$down_num==0||$pj==0)
        {
			$nbsp="";
		}
        else
        {
			$nbsp="&nbsp;&nbsp;";
		}
	    $showdown_r=explode("::::::",$path_r[$pj]);
	    if(count($showdown_r)<2)
		{
			$showdown_r[0]=$p;
		}
		//模板
		$downsofttemp=RepDownOnlinePathTemp($add,$public_r[onlinemovietemp],$pj,$showdown_r,1);
        $all_downpath.=$nbsp.stripSlashes($downsofttemp).$ok;
	}
	$value=$all_downpath;
	return $value;
}

//返回图片集html代码
function ReturnMorepicpathHtml($add){
	global $public_r,$fun_r;
	if(empty($add[morepic]))
	{
		return "";
	}
	$line=$add[num];//每行显示
	if(empty($line))
	{
		$line=1;
	}
	$picpath="";
	$path_r=explode("\r\n",$add[morepic]);
	for($pj=0;$pj<count($path_r);$pj++)
    {
		$p=$pj+1;
		if(($p-1)%$line==0||$p==1)
		{
			$picpath.="<tr>";
		}
	    $showdown_r=explode("::::::",$path_r[$pj]);
		//显示图片名称
		$name="";
		if(!empty($showdown_r[2]))
		{
			$name="<br><span style='line-height=18pt'>".$showdown_r[2]."</span>";
		}
		//宽度
		if($add[width])
		{
			$width=" width='".$add[width]."'";
		}
		else
		{
			$width="";
		}
		//高度
		if($add[height])
		{
			$height=" height='".$add[height]."'";
		}
		else
		{
			$height="";
		}
		$picpath.="<td align=center><a href='".$public_r[newsurl]."e/ViewImg/index.html?url=".$showdown_r[1]."' target=_blank><img src='".$showdown_r[0]."'".$width.$height." border=0>".$name."</a></td>";
		//分割
        if($p%$line==0)
		{$picpath.="</tr>";}
	}
	if($p<>0)
	{
		$table="<table width='100%' border=0 cellpadding=4 cellspacing=4>";$table1="</table>";
        $ys=$line-$p%$line;
		$dotr=0;
        for($j=0;$j<$ys&&$ys!=$line;$j++)
		{
			$dotr=1;
            $picpath.="<td></td>";
        }
		if($dotr==1)
		{
			$picpath.="</tr>";
		}
	}
	$value=$table.$picpath.$table1;
	return $value;
}

//替换特殊标记
function ReplaceSvars($temp1,$classid,$title,$url,$enews=0){
	global $public_r,$class_r,$class_zr;
	$allpath=$public_r[newsurl].'d/js/js/';
	if($enews==1)//专题js
	{
		$path=$public_r['newsurl'].'d/js/class/zt'.$classid.'_';
    }
	else//栏目js
	{
		$path=$public_r['newsurl'].'d/js/class/class'.$classid.'_';
    }
	//热门文章
	$temp1=str_replace("[!--hotnews--]","<script src='".$allpath."hotnews.js'></script>",$temp1);
	$temp1=str_replace("[!--self.hotnews--]","<script src='".$path."hotnews.js'></script>",$temp1);
	//点击排行
	$temp1=str_replace("[!--newnews--]","<script src='".$allpath."newnews.js'></script>",$temp1);
	$temp1=str_replace("[!--self.newnews--]","<script src='".$path."newnews.js'></script>",$temp1);
	//推荐
	$temp1=str_replace("[!--goodnews--]","<script src='".$allpath."goodnews.js'></script>",$temp1);
	$temp1=str_replace("[!--self.goodnews--]","<script src='".$path."goodnews.js'></script>",$temp1);
	//评论排行
	$temp1=str_replace("[!--hotplnews--]","<script src='".$allpath."hotplnews.js'></script>",$temp1);
	$temp1=str_replace("[!--self.hotplnews--]","<script src='".$path."hotplnews.js'></script>",$temp1);
	//头条排行
	$temp1=str_replace("[!--firstnews--]","<script src='".$allpath."firstnews.js'></script>",$temp1);
	$temp1=str_replace("[!--self.firstnews--]","<script src='".$path."firstnews.js'></script>",$temp1);
	//栏目导航
	$temp1=str_replace("[!--newsnav--]",$url,$temp1);
	//页面标题
	$temp1=str_replace("[!--pagetitle--]",$title,$temp1);
	return $temp1;
}

//组合标题属性
function TitleFont($titlefont,$titlecolor=''){
	$add=$titlecolor.',';
	if($titlecolor=='no')
	{
		$add='';
	}
	if($titlefont[b])//粗体
	{$add.='b|';}
	if($titlefont[i])//斜体
	{$add.='i|';}
	if($titlefont[s])//删除线
	{$add.='s|';}
	if($add==',')
	{
		$add='';
	}
	return $add;
}

//组合专题ID
function ZtId($ztid){
	$myztid="|";
	for($i=0;$i<count($ztid);$i++)
	{
		$myztid.=$ztid[$i]."|";
	}
	return $myztid;
}

//图片集上传图片
function SaveMorepicFile($varname,$msavepic,$i,$picurl,$picname,$classid,$id,$add){
	global $public_r,$empire,$loginin,$dbtbpre,$tranpicturetype;
	if($varname=="mbigpfile")
	{
		$addname="[b]";
	}
	$type=1;
	$r[url]=$picurl;
	//上传
	if($_FILES[$varname]['name'][$i])
	{
		//取得文件类型
		$filetype=GetFiletype($_FILES[$varname]['name'][$i]);
		//允许上传类型
		if(CheckSaveTranFiletype($filetype))
		{
			return $r;
		}
		if(!strstr($public_r['filetype'],"|".$filetype."|"))
		{
			return $r;
		}
		//图片文件
		if(!strstr($tranpicturetype,','.$filetype.','))
		{
			return $r;
		}
		//文件大小
		if($_FILES[$varname]['size'][$i]>$public_r['filesize']*1024)
		{
			return $r;
		}
		//上传
		$r=DoTranFile($_FILES[$varname]['tmp_name'][$i],$_FILES[$varname]['name'][$i],$_FILES[$varname]['type'][$i],$_FILES[$varname]['size'][$i],$classid);
		//------------------------写入数据库
		$r[filesize]=(int)$r[filesize];
		$classid=(int)$classid;
		$filetime=date("Y-m-d H:i:s");
		if(empty($picname))
		{
			$picname=$r[filename];
		}
		else
		{
			$picname=$addname.$picname;
		}
		$picname=RepPostStr($picname);
		$id=(int)$id;
		$cjid=0;
		if(!$id)
		{
			$cjid=(int)$add['filepass'];
		}
		$sql=$empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,onclick,id,cjid,fpath) values('$r[filename]',$r[filesize],'$loginin','$r[filepath]','$filetime',$classid,'$picname',$type,0,$id,$cjid,'$public_r[fpath]');");
		return $r;
	}
	//远程保存
	else
	{
		if(empty($msavepic))
		{
			return $r;
		}
		if(empty($picurl))
		{
			return $r;
		}
		//----------------取得文件类型
		$filetype=GetFiletype($picurl);
		//允许上传类型
		if(CheckSaveTranFiletype($filetype))
		{
			return $r;
		}
		if(!strstr($public_r['filetype'],"|".$filetype."|"))
		{
			return $r;
		}
		//图片文件
		if(!strstr($tranpicturetype,','.$filetype.','))
		{
			return $r;
		}
		//保存
		$r=DoTranUrl($picurl,$classid);
		if($r['tran'])
		{
			//记录数据库
			$filetime=date("Y-m-d H:i:s");
			//变量处理
			$r[filesize]=(int)$r[filesize];
			$classid=(int)$classid;
			$r[type]=(int)$r[type];
			if(empty($picname))
			{
				$picname=$r[filename];
			}
			else
			{
				$picname=$addname.$picname;
			}
			$picname=RepPostStr($picname);
			$id=(int)$id;
			$cjid=0;
			if(!$id)
			{
				$cjid=(int)$add['filepass'];
			}
			$sql=$empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,id,cjid,onclick,fpath) values('$r[filename]',$r[filesize],'$loginin','$r[filepath]','$filetime',$classid,'$picname',$type,$id,$cjid,0,'$public_r[fpath]');");
			return $r;
		}
		return $r;
	}
}

//入库时远程保存
function LoadInSaveMorepicFile($morepic,$msavepic,$classid,$id,$add){
	if(empty($morepic)||!$msavepic)
	{
		return $morepic;
	}
	$f_exp="::::::";
	$r_exp="\r\n";
	$returnstr="";
	$r=explode($r_exp,$morepic);
	$countr=count($r);
	for($i=0;$i<$countr;$i++)
	{
		$r1=explode($f_exp,$r[$i]);
		//小图
		$smpr=SaveMorepicFile("msmallpfile",$msavepic,0,$r1[0],$r1[2],$classid,$id,$add);
		$spic=$smpr[url];
		//大图
		if($r1[0]!=$r1[1])
		{
			$bmpr=SaveMorepicFile("mbigpfile",$msavepic,0,$r1[1],$r1[2],$classid,$id,$add);
			$bpic=$bmpr[url];
		}
		else
		{
			$bpic=$spic;
		}
		if($spic)
		{
			$returnstr.=$spic.$f_exp.$bpic.$f_exp.$r1[2].$r_exp;
		}
	}
	//去掉最后的字符
	$returnstr=substr($returnstr,0,strlen($returnstr)-2);
	return $returnstr;
}

//---------图片地址组合
function ReturnMorepicpath($smallpic,$bigpic,$picname,$delpicid,$picid,$add,$downurl,$down=0){
	global $loginin,$logininid;
	$f_exp="::::::";
	$r_exp="\r\n";
	$returnstr="";
    $downurl=str_replace($f_exp,"",$downurl);
	$downurl=str_replace($r_exp,"",$downurl);
	//增加信息
	if(empty($down))
	{
		for($i=0;$i<count($smallpic);$i++)
		{
			$name=str_replace($f_exp,"",$picname[$i]);
			$name=str_replace($r_exp,"",$name);
			//替换非法字符
			$spic=str_replace($f_exp,"",$smallpic[$i]);
			$spic=str_replace($r_exp,"",$spic);
			$spic=$spic?$downurl.$spic:'';
			//保存图片
			$smpr=SaveMorepicFile("msmallpfile",$add[msavepic],$i,$spic,$name,$add[classid],$add[id],$add);
			$spic=$smpr[url];

			//如没有大图的话跟缩略图一样
			if(empty($bigpic[$i])&&!$_FILES['mbigpfile']['name'][$i])
			{
				$bpic=$spic;
			}
			else
			{
				$bpic=str_replace($f_exp,"",$bigpic[$i]);
				$bpic=str_replace($r_exp,"",$bpic);
				$bpic=$bpic?$downurl.$bpic:'';
				//保存图片
				$bmpr=SaveMorepicFile("mbigpfile",$add[msavepic],$i,$bpic,$name,$add[classid],$add[id],$add);
				$bpic=$bmpr[url];
				//生成缩图
				if(empty($spic)&&$bpic&&$bmpr[tran]&&$add[mcreatespic])
				{
					$picno='[b]'.($name?$name:$bmpr[filename]);
					$sfiler=GetMySmallImg($add['classid'],$picno,$bmpr[insertfile],$bmpr[filepath],$bmpr[yname],$add[mcreatespicwidth],$add[mcreatespicheight],$bmpr[name],$add['filepass'],$add['filepass'],$logininid,$loginin);
					$spic=str_replace("/".$bmpr[filename],"/small".$bmpr[insertfile].$sfiler['filetype'],$bmpr[url]);
				}
			}
			if(empty($spic))
			{
				$spic=$bpic;
			}
			if($spic)
			{$returnstr.=$spic.$f_exp.$bpic.$f_exp.$name.$r_exp;}
		}
	}
	//修改信息
	else
	{
		for($i=0;$i<count($smallpic);$i++)
		{
			//删除地址
			$del=0;
			for($j=0;$j<count($delpicid);$j++)
			{
				if($delpicid[$j]==$picid[$i])
				{$del=1;}
			}
			if($del)
			{continue;}
			$name=str_replace($f_exp,"",$picname[$i]);
			$name=str_replace($r_exp,"",$name);
			//替换非法字符
			$spic=str_replace($f_exp,"",$smallpic[$i]);
			$spic=str_replace($r_exp,"",$spic);
			$spic=$spic?$downurl.$spic:'';
			//保存图片
			$smpr=SaveMorepicFile("msmallpfile",$add[msavepic],$i,$spic,$name,$add[classid],$add[id],$add);
			$spic=$smpr[url];

			//如没有大图的话跟缩略图一样
			if(empty($bigpic[$i])&&!$_FILES['mbigpfile']['name'][$i])
			{
				$bpic=$spic;
			}
			else
			{
				$bpic=str_replace($f_exp,"",$bigpic[$i]);
				$bpic=str_replace($r_exp,"",$bpic);
				$bpic=$bpic?$downurl.$bpic:'';
				//保存图片
				$bmpr=SaveMorepicFile("mbigpfile",$add[msavepic],$i,$bpic,$name,$add[classid],$add[id],$add);
				$bpic=$bmpr[url];
				//生成缩图
				if(empty($spic)&&$bpic&&$bmpr[tran]&&$add[mcreatespic])
				{
					$picno='[b]'.($name?$name:$bmpr[filename]);
					$sfiler=GetMySmallImg($add['classid'],$picno,$bmpr[insertfile],$bmpr[filepath],$bmpr[yname],$add[mcreatespicwidth],$add[mcreatespicheight],$bmpr[name],$add['filepass'],$add['filepass'],$logininid,$loginin);
					$spic=str_replace("/".$bmpr[filename],"/small".$bmpr[insertfile].$sfiler['filetype'],$bmpr[url]);
				}
			}
			if(empty($spic))
			{
				$spic=$bpic;
			}
			if($spic)
			{$returnstr.=$spic.$f_exp.$bpic.$f_exp.$name.$r_exp;}
		}
	}
	//去掉最后的字符
	$returnstr=substr($returnstr,0,strlen($returnstr)-2);
	return $returnstr;
}

//---------下载地址组合
function ReturnDownpath($downname,$downpath,$delpathid,$pathid,$downuser,$fen,$thedownqz,$add,$foruser,$downurl,$down=0){
	$f_exp="::::::";
	$r_exp="\r\n";
	$returnstr="";
    $downurl=str_replace($f_exp,"",$downurl);
	$downurl=str_replace($r_exp,"",$downurl);
	//增加软件
	if(empty($down))
	{
		for($i=0;$i<count($downname);$i++)
		{
			//替换非法字符
			$name=str_replace($f_exp,"",$downname[$i]);
			$name=str_replace($r_exp,"",$downname[$i]);
			$path=str_replace($f_exp,"",$downpath[$i]);
			$path=str_replace($r_exp,"",$downpath[$i]);
			//批量更换权限
			if($add[doforuser])
			{
				if(empty($foruser))
				{
					$foruser=0;
			    }
				$fuser=$foruser;
		    }
			else
			{
				if(empty($downuser[$i]))
				{
					$fuser=0;
			    }
				else
				{
					$fuser=$downuser[$i];
				}
		    }
			//批量更新点数
			if($add[dodownfen])
			{
				if(empty($add[downfen]))
				{
					$add[downfen]=0;
				}
				$ffen=$add[downfen];
			}
			else
			{
				if(empty($fen[$i]))
				{
					$ffen=0;
				}
				else
				{
					$ffen=$fen[$i];
				}
			}
			$downqz=$thedownqz[$i];
			if($path&&$name)
			{$returnstr.=$name.$f_exp.$downurl.$path.$f_exp.$fuser.$f_exp.$ffen.$f_exp.$downqz.$r_exp;}
		}
	}
	//修改软件
	else
	{
		for($i=0;$i<count($downname);$i++)
		{
			//删除下载地址
			$del=0;
			for($j=0;$j<count($delpathid);$j++)
			{
				if($delpathid[$j]==$pathid[$i])
				{$del=1;}
			}
			if($del)
			{continue;}
			//替换非法字符
			$name=str_replace($f_exp,"",$downname[$i]);
			$name=str_replace($r_exp,"",$downname[$i]);
			$path=str_replace($f_exp,"",$downpath[$i]);
			$path=str_replace($r_exp,"",$downpath[$i]);
			//批量更换权限
			if($add[doforuser])
			{
				if(empty($foruser))
				{
					$foruser=0;
			    }
				$fuser=$foruser;
		    }
			else
			{
				if(empty($downuser[$i]))
				{
					$fuser=0;
			    }
				else
				{
					$fuser=$downuser[$i];
				}
		    }
			//批量更新点数
			if($add[dodownfen])
			{
				if(empty($add[downfen]))
				{
					$add[downfen]=0;
				}
				$ffen=$add[downfen];
			}
			else
			{
				if(empty($fen[$i]))
				{
					$ffen=0;
				}
				else
				{
					$ffen=$fen[$i];
				}
			}
			$downqz=$thedownqz[$i];
			if($path&&$name)
			{$returnstr.=$name.$f_exp.$downurl.$path.$f_exp.$fuser.$f_exp.$ffen.$f_exp.$downqz.$r_exp;}
		}
	}
	//去掉最后的字符
	$returnstr=substr($returnstr,0,strlen($returnstr)-2);
	return $returnstr;
}

//替换文件前缀
function RepFilenameQz($qz)
{
	$qz=str_replace("/","",$qz);
	$qz=str_replace("\\","",$qz);
	$qz=str_replace("#","",$qz);
	$qz=str_replace("&","",$qz);
	$qz=str_replace(":","",$qz);
	$qz=str_replace(";","",$qz);
	$qz=str_replace("<","",$qz);
	$qz=str_replace(">","",$qz);
	$qz=str_replace("?","",$qz);
	$qz=str_replace("*","",$qz);
	$qz=str_replace("%","",$qz);
	$qz=str_replace("|","",$qz);
	$qz=str_replace("\"","",$qz);
	$qz=str_replace("'","",$qz);
	return $qz;
}

//更新相应的附件
function UpdateTheFile($id,$checkpass){
	global $empire,$dbtbpre;
	if(empty($id)||empty($checkpass))
	{
		return "";
    }
	$id=(int)$id;
	$checkpass=(int)$checkpass;
	$sql=$empire->query("update {$dbtbpre}enewsfile set id=$id,cjid=0 where cjid=$checkpass");
}

//修改时更新附件
function UpdateTheFileEdit($classid,$id){
	global $empire,$dbtbpre;
	$sql=$empire->query("update {$dbtbpre}enewsfile set cjid=0 where id='$id' and classid='$classid'");
}

//返回命名方式
function ReturnInfoFilename($classid,$id,$filenameqz){
	global $class_r;
	if($class_r[$classid][filename]==1)	//time命名
	{
		$filename=$class_r[$classid][filename_qz].time().$id;
	}
	elseif($class_r[$classid][filename]==2)	//md5命名
	{
		$filename=$class_r[$classid][filename_qz].md5(uniqid(microtime()));
	}
	elseif($class_r[$classid][filename]==3)	//目录
	{
		$filename=$class_r[$classid][filename_qz].$id.'/index';
	}
	else	//id
	{
		$filename=$class_r[$classid][filename_qz].$id;
	}
	$filename=$filenameqz.$filename;
	return $filename;
}

//取第几张图片
function GetFpicToTpic($classid,$id,$num=1,$getfirsttitlespic=0,$swidth=0,$sheight=0){
	global $empire,$dbtbpre,$public_r,$class_r;
	$num=$num-1;
	$picr=$empire->fetch1("select fileid,filename,path,id,classid,no,fpath from {$dbtbpre}enewsfile where id=$id and classid=$classid and type=1 order by fileid limit $num,1");
	$firsttitlepic="";
	if($picr['fileid'])
	{
		$rpath=$picr['path']?$picr['path'].'/':$picr['path'];
		$fspath=ReturnFileSavePath($picr[classid],$picr[fpath]);
		if($getfirsttitlespic==1&&$swidth&&$sheight)//缩略图
		{
			$path="../../".$fspath['filepath'].$rpath;
			$yname=$path.$picr[filename];
			$filetype=GetFiletype($picr[filename]);
			$insertfile=substr($picr[filename],0,strlen($picr[filename])-strlen($filetype));
			$name=$path."small".$insertfile;
			$sfiler=GetMySmallImg($classid,$picr[no],$insertfile,$picr[path],$yname,$swidth,$sheight,$name,$add['filepass'],$add['filepass'],$userid,$username);
			$firsttitlepic=$fspath['fileurl'].$rpath."small".$insertfile.$sfiler['filetype'];
		}
		else
		{
			$firsttitlepic=$fspath['fileurl'].$rpath.$picr[filename];
		}
	}
	return $firsttitlepic;
}

//返回相关链接信息ID
function GetKeyid($keyboard,$classid,$id,$link_num){
	global $empire,$public_r,$class_r,$fun_r,$dbtbpre;
	if($keyboard)
	{
		if(empty($link_num))
		{
			$link_num=10;
		}
		$keyboard=RepDyh($keyboard);
		$r=explode(",",$keyboard);
		for($i=0;$i<count($r);$i++)
		{
			if($i==0)
			{
				$or="";
			}
			else
			{
				$or=" or ";
			}
			$repadd.=$or."[!--f--!]"." like '%".$r[$i]."%'";
	    }
		//搜索范围
		if($public_r['newslink']==1)
		{
			$add='('.str_replace('[!--f--!]','keyboard',$repadd).')';
		}
		elseif($public_r['newslink']==2)
		{
			$add='('.str_replace('[!--f--!]','keyboard',$repadd).' or '.str_replace('[!--f--!]','title',$repadd).')';
		}
		else
		{
			$add='('.str_replace('[!--f--!]','title',$repadd).')';
		}
		//模型
		if(!empty($class_r[$classid][modid]))
		{
			$mr=$empire->fetch1("select sonclass from {$dbtbpre}enewsmod where mid='".$class_r[$classid][modid]."'");
			$where=" and (".ReturnClass($mr[sonclass]).")";
		}
		//ID声名
		$keyid="";
		$first=0;
		$key_sql=$empire->query("select id from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where ".$add.$where." and id<>$id and checked=1 order by newstime desc limit $link_num");
		while($link_r=$empire->fetch($key_sql))
		{
			if(empty($first))
			{
				$dh="";
				$first=1;
			}
			else
			{
				$dh=",";
			}
			$keyid.=$dh.$link_r[id];
		}
	}
	else
	{
		$keyid="";
	}
	return $keyid;
}

//批量更新相关链接
function ChangeInfoOtherLink($start,$classid,$from,$retype,$startday,$endday,$startid,$endid,$tbname,$userid,$username){
	global $empire,$public_r,$class_r,$fun_r,$dbtbpre;
	//验证权限
	CheckLevel($userid,$username,$classid,"changedata");
	$start=(int)$start;
	$tbname=RepPostVar($tbname);
	if(empty($tbname))
	{
		printerror("ErrorUrl","history.go(-1)");
    }
	//按栏目刷新
	$classid=(int)$classid;
	if($classid)
	{
		if(empty($class_r[$classid][islast]))//父栏目
		{
			$where=ReturnClass($class_r[$classid][sonclass]);
		}
		else//终极栏目
		{
			$where="classid='$classid'";
		}
		$add1=" and (".$where.")";
    }
	//按ID刷新
	if($retype)
	{
		$startid=(int)$startid;
		$endid=(int)$endid;
		if($endid)
		{
			$add1.=" and id>=$startid and id<=$endid";
	    }
    }
	else
	{
		$startday=RepPostVar($startday);
		$endday=RepPostVar($endday);
		if($startday&&$endday)
		{
			$add1.=" and truetime>=".to_time($startday." 00:00:00")." and truetime<=".to_time($endday." 23:59:59");
	    }
    }
	$b=0;
	$sql=$empire->query("select id,keyboard,classid from {$dbtbpre}ecms_".$tbname." where id>$start".$add1." order by id limit ".$public_r[infolinknum]);
	while($r=$empire->fetch($sql))
	{
		$b=1;
		$new_start=$r[id];
		$newkeyid=GetKeyid($r[keyboard],$r[classid],$r[id],$class_r[$r[classid]][link_num]);
		$usql=$empire->query("update {$dbtbpre}ecms_".$tbname." set keyid='$newkeyid' where id=$r[id]");
	}
	if(empty($b))
	{
	    insert_dolog("");//操作日志
		printerror("ChangeInfoLinkSuccess",$from);
	}
	echo $fun_r[OneChangeInfoLinkSuccess]."(ID:<font color=red><b>".$new_start."</b></font>)<script>self.location.href='enews.php?enews=ChangeInfoOtherLink&tbname=$tbname&classid=$classid&start=$new_start&from=$from&retype=$retype&startday=$startday&endday=$endday&startid=$startid&endid=$endid';</script>";
	exit();
}

//取得相关链接
function GetKeyboard($keyboard,$keyid,$classid,$id,$link_num){
	global $empire,$public_r,$class_r,$fun_r,$dbtbpre;
	if($keyid)
	{
		if(empty($link_num))
		{
			$link_num=10;
		}
		$add="id in (".$keyid.")";
		$tr=$empire->fetch1("select otherlinktemp,otherlinktempsub,otherlinktempdate from ".GetTemptb("enewspubtemp")." limit 1");//取得相关链接模板
		$temp_r=explode("[!--empirenews.listtemp--]",$tr[otherlinktemp]);
		$key_sql=$empire->query("select id,newspath,newstime,title,filename,titleurl,groupid,classid,titlepic from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where ".$add." order by newstime desc limit $link_num");
		while($link_r=$empire->fetch($key_sql))
		{
			$keyboardtext.=RepOtherTemp($temp_r[1],$link_r,$tr);
		}
		$keyboardtext=$temp_r[0].$keyboardtext.$temp_r[2];
	}
	else
	{
		$keyboardtext=$fun_r['NotLinkNews'];
	}
	return $keyboardtext;
}

//替换相关链接模板
function RepOtherTemp($temptext,$r,$tr){
	global $public_r,$class_r;
	$title=sub($r[title],0,$tr['otherlinktempsub'],false);
	$r['newstime']=format_datetime($r['newstime'],$tr['otherlinktempdate']);
	$titlelink=sys_ReturnBqTitleLink($r);//标题链接
	$temptext=str_replace("[!--title--]",$title,$temptext);
	$temptext=str_replace("[!--oldtitle--]",$r[title],$temptext);
	$temptext=str_replace("[!--titleurl--]",$titlelink,$temptext);
	$temptext=str_replace("[!--newstime--]",$r[newstime],$temptext);
	if(empty($r[titlepic]))
	{
		$titlepic=$public_r[newsurl]."e/data/images/notimg.gif";
	}
	else
	{
		$titlepic=$r[titlepic];
	}
	$temptext=str_replace("[!--titlepic--]",$titlepic,$temptext);
	return $temptext;
}

//删除信息附件
function DelNewsTheFile($id,$classid){
	global $empire,$dbtbpre;
	if(empty($id))
	{
		return "";
	}
	$i=0;
	$sql=$empire->query("select classid,filename,path,fpath from {$dbtbpre}enewsfile where id='$id' and classid='$classid'");
	while($r=$empire->fetch($sql))
	{
		$i=1;
		DoDelFile($r);
    }
	if($i)
	{
		$delsql=$empire->query("delete from {$dbtbpre}enewsfile where id='$id' and classid='$classid'");
	}
	//删除评论
	$delplsql=$empire->query("delete from {$dbtbpre}enewspl where id='$id' and classid='$classid'");
}

//返回操作权限
function ReturnLeftLevel($groupid){
	global $empire,$dbtbpre;
	if(empty($groupid))
	{return "";}
	$groupid=(int)$groupid;
	$r=$empire->fetch1("select * from {$dbtbpre}enewsgroup where groupid='$groupid'");
	return $r;
}

//返回操作权限
function CheckLevel($userid,$username,$classid,$enews){
	global $empire,$dbtbpre;
	$userid=(int)$userid;
	$r=$empire->fetch1("select groupid,adminclass from {$dbtbpre}enewsuser where userid='$userid' limit 1");
	//操作信息
	if($enews=="news")
	{
		//操作所有栏目权限
		$gr=$empire->fetch1("select doall,doselfinfo,doaddinfo,doeditinfo,dodelinfo from {$dbtbpre}enewsgroup where groupid='$r[groupid]'");
		if(empty($gr[doall]))
		{
			$e_r=explode("|".$classid."|",$r[adminclass]);
			if(count($e_r)!=2)
			{printerror("NotNewsLevel","history.go(-1)");}
		}
		return $gr;
    }
	else
	{
		//用户组
		$gr=$empire->fetch1("select * from {$dbtbpre}enewsgroup where groupid='$r[groupid]'");
		$enews="do".$enews;
		if(empty($gr[$enews]))
		{
			printerror("NotLevel","history.go(-1)");
	    }
    }
}

//取得内容模板
function GetNewsTemp($newstempid){
	global $empire,$public_r;
	$r=$empire->fetch1("select temptext,showdate from ".GetTemptb("enewsnewstemp")." where tempid='$newstempid'");
	$r[temptext]=NewsBq("news".$newstempid,$r[temptext],2,0);
	//启用反采集
	if($public_r[opennotcj])
	{
		$r[temptext]=ReturnNotcj($r[temptext]);
    }
	return $r;
}

//删除信息文件
function DelNewsFile($filename,$newspath,$classid,$newstext,$groupid=0){
	global $class_r,$addgethtmlpath;
	//文件类型
	if($groupid)
	{
		$filetype=".php";
	}
	else
	{
		$filetype=$class_r[$classid][filetype];
	}
	//是否有日期目录
	if(empty($newspath))
	{
		$mynewspath="";
    }
	else
	{
		$mynewspath=$newspath."/";
    }
	$iclasspath=ReturnSaveInfoPath($classid,$id);
	$r=explode("[!--empirenews.page--]",$newstext);
	for($i=1;$i<=count($r);$i++)
	{
		if(strstr($filename,'/'))
		{
			DelPath($addgethtmlpath."../../".$iclasspath.$mynewspath.ReturnInfoSPath($filename));
		}
		else
		{
			if($i==1)
			{
				$file=$addgethtmlpath."../../".$iclasspath.$mynewspath.$filename.$filetype;
			}
			else
			{
				$file=$addgethtmlpath."../../".$iclasspath.$mynewspath.$filename."_".$i.$filetype;
			}
			DelFiletext($file);
		}
	}
}

//是否登陆
function is_login($userid,$username,$rnd){
	global $empire,$public_r,$dbtbpre;
	eCheckAccessIp(1);//禁止IP
	$userid=(int)$userid;
	$username=RepPostVar($username);
	if(!$userid||!$username)
	{
		printerror("NotLogin","index.php");
	}
	$rnd=RepPostVar($rnd);
	//COOKIE验证
	if(getcvar('loginusername'))
	{
		$cdbdata=getcvar('ecmsdodbdata')?1:0;
		$groupid=(int)getcvar('loginlevel');
		$adminstyle=(int)getcvar('loginadminstyleid');
		DoChECookieRnd($userid,$username,$rnd,$cdbdata,$groupid,$adminstyle);
	}
	//db
	$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsuser where username='".$username."' and rnd='".$rnd."' and checked=0 limit 1");
	if(!$num)
	{
		printerror("SingleUser","index.php");
	}
	//登陆超时
	$logintime=getcvar('logintime');
	if($logintime)
	{
		if(time()-$logintime>$public_r['exittime']*60)
		{
			printerror("LoginTime","index.php");
	    }
		$set=esetcookie("logintime",time(),0);
	}
	if(getcvar('eloginlic')<>"empirecmslic")
	{
		printerror("NotLogin","index.php");
	}
}

function is_login_ebak($userid,$username,$rnd){
	global $empire,$public_r;
	eCheckAccessIp(1);//禁止IP
	$userid=(int)$userid;
	$username=RepPostVar($username);
	$dodbdata=getcvar('ecmsdodbdata');
	if(!$userid||!$username)
	{
		printerror("NotLogin","index.php");
	}
	if($dodbdata!="empirecms")
	{
		printerror("NotLogin","index.php");
	}
	$rnd=RepPostVar($rnd);
	//COOKIE验证
	$cdbdata=$dodbdata?1:0;
	$groupid=(int)getcvar('loginlevel');
	$adminstyle=(int)getcvar('loginadminstyleid');
	DoChECookieRnd($userid,$username,$rnd,$cdbdata,$groupid,$adminstyle);
	//超时
	$logintime=getcvar('logintime');
	if($logintime)
	{
		if(time()-$logintime>$public_r['exittime']*60)
		{
			printerror("LoginTime","index.php");
	    }
		$set=esetcookie("logintime",time(),0);
	}
}

//错误登陆记录
function InsertErrorLoginNum($username,$password,$loginauth,$ip,$time){
	global $empire,$public_r,$dbtbpre;
	//COOKIE
	$loginnum=intval(getcvar('loginnum'));
	$logintime=$time;
	$lastlogintime=getcvar('lastlogintime');
	if($lastlogintime&&($logintime-$lastlogintime>$public_r['logintime']*60))
	{
		$loginnum=0;
	}
	$loginnum++;
	esetcookie("loginnum",$loginnum,$logintime+3600*24);
	esetcookie("lastlogintime",$logintime,$logintime+3600*24);
	//数据库
	$chtime=$time-$public_r['logintime']*60;
	$empire->query("delete from {$dbtbpre}enewsloginfail where lasttime<$chtime");
	$r=$empire->fetch1("select ip from {$dbtbpre}enewsloginfail where ip='$ip' limit 1");
	if($r['ip'])
	{
		$empire->query("update {$dbtbpre}enewsloginfail set num=num+1,lasttime='$time' where ip='$ip' limit 1");
	}
	else
	{
		$empire->query("insert into {$dbtbpre}enewsloginfail(ip,num,lasttime) values('$ip',1,'$time');");
	}
	//日志
	insert_log($username,$password,0,$ip,$loginauth);
}

//验证登录次数
function CheckLoginNum($ip,$time){
	global $empire,$public_r,$dbtbpre;
	//COOKIE验证
	$loginnum=getcvar('loginnum');
	$lastlogintime=getcvar('lastlogintime');
	if($lastlogintime)
	{
		if($time-$lastlogintime<$public_r['logintime']*60)
		{
			if($loginnum>=$public_r['loginnum'])
			{
				printerror("LoginOutNum","history.go(-1)");
			}
		}
	}
	//数据库验证
	$chtime=$time-$public_r['logintime']*60;
	$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsloginfail where ip='$ip' and num>=$public_r[loginnum] and lasttime>$chtime limit 1");
	if($num)
	{
		printerror("LoginOutNum","history.go(-1)");
	}
}

//COOKIE加密
function DoECookieRnd($userid,$username,$rnd,$dbdata,$groupid,$adminstyle){
	global $do_ecookiernd;
	$ecmsckpass=md5(md5($rnd.$do_ecookiernd).'-'.$userid.'-'.$username.'-'.$dbdata.$rnd.$groupid.'-'.$adminstyle);
	esetcookie("loginecmsckpass",$ecmsckpass,0);
}

function DoChECookieRnd($userid,$username,$rnd,$dbdata,$groupid,$adminstyle){
	global $do_ecookiernd;
	$ecmsckpass=md5(md5($rnd.$do_ecookiernd).'-'.$userid.'-'.$username.'-'.$dbdata.$rnd.$groupid.'-'.$adminstyle);
	if($ecmsckpass<>getcvar('loginecmsckpass'))
	{
		printerror("NotLogin","index.php");
	}
}

//登陆
function login($username,$password,$key,$post){
	global $empire,$public_r,$dbtbpre,$do_loginauth;
	eCheckAccessIp(1);//禁止IP
	$username=RepPostVar($username);
	$password=RepPostVar($password);
	if(!$username||!$password)
	{
		printerror("EmptyKey","index.php");
	}
	//验证码
	if(!$public_r['adminloginkey'])
	{
		$checkkey=getcvar('checkkey');
		if(!$checkkey||$key<>$checkkey)
		{
			printerror("ErrorKey","index.php");
		}
	}
	if(strlen($username)>30||strlen($password)>30)
	{
		printerror("EmptyKey","index.php");
	}
	$loginip=egetip();
	$logintime=time();
	CheckLoginNum($loginip,$logintime);
	//认证码
	if($do_loginauth&&$do_loginauth!=$post['loginauth'])
	{
		InsertErrorLoginNum($username,$password,1,$loginip,$logintime);
		printerror("ErrorLoginAuth","index.php");
	}
	$user_r=$empire->fetch1("select userid,password,salt from {$dbtbpre}enewsuser where username='".$username."' and checked=0 limit 1");
	if(!$user_r['userid'])
	{
		InsertErrorLoginNum($username,$password,0,$loginip,$logintime);
		printerror("LoginFail","index.php");
	}
	$ch_password=md5(md5($password).$user_r['salt']);
	if($user_r['password']!=$ch_password)
	{
		InsertErrorLoginNum($username,$password,0,$loginip,$logintime);
		printerror("LoginFail","index.php");
	}
	//取得随机密码
	$rnd=make_password(20);
	$sql=$empire->query("update {$dbtbpre}enewsuser set rnd='$rnd',loginnum=loginnum+1,lastip='$loginip',lasttime='$logintime' where username='$username' limit 1");
	$r=$empire->fetch1("select groupid,userid,styleid from {$dbtbpre}enewsuser where username='$username' limit 1");
	//样式
	if(empty($r[styleid]))
	{
		$stylepath=$public_r['defadminstyle']?$public_r['defadminstyle']:1;
	}
	else
	{
		$styler=$empire->fetch1("select path,styleid from {$dbtbpre}enewsadminstyle where styleid='$r[styleid]'");
		if(empty($styler[styleid]))
		{
			$stylepath=$public_r['defadminstyle']?$public_r['defadminstyle']:1;
		}
		else
		{
			$stylepath=$styler['path'];
		}
	}
	//设置备份 先检查数据库中有备份权利的用户组然后设置cookie记录该用户组
	$cdbdata=0;
	$bnum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsgroup where groupid='$r[groupid]' and dodbdata=1");
	if($bnum)
	{
		$cdbdata=1;
		$set5=esetcookie("ecmsdodbdata","empirecms",0);
    }
	else
	{
		$set5=esetcookie("ecmsdodbdata","",0);
	}
	
	$setkey=esetcookie("checkkey","");
	$set4=esetcookie("loginuserid",$r[userid],0);
	$set1=esetcookie("loginusername",$username,0);
	$set2=esetcookie("loginrnd",$rnd,0);
	$set3=esetcookie("loginlevel",$r[groupid],0);
	$set5=esetcookie("eloginlic","empirecmslic",0);
	$set6=esetcookie("loginadminstyleid",$stylepath,0);
	//COOKIE加密验证
	DoECookieRnd($r[userid],$username,$rnd,$cdbdata,$r[groupid],intval($stylepath));
	//最后登陆时间
	$set4=esetcookie("logintime",$logintime,0);
	//写入日志
	insert_log($username,'',1,$loginip,0);
	if($set1&&$set2&&$set3)
	{
		//操作日志
	    insert_dolog("");
		if($post['adminwindow'])
		{
		?>
			<script>
			AdminWin=window.open("admin.php","EmpireCMS","scrollbars");
			AdminWin.moveTo(0,0);
			AdminWin.resizeTo(screen.width,screen.height-30);
			self.location.href="blank.php";
			</script>
		<?
		exit();
		}
		else
		{
			printerror("LoginSuccess","admin.php");
		}
	}
	else
	{
		printerror("NotCookie","index.php");
	}
}

//修改首页模板
function EditIndextemp($temptext,$userid,$username){
	global $empire,$dbtbpre,$public_r;
	if(!$temptext)
	{
		printerror("EmptyIndexTemp","history.go(-1)");
	}
	CheckLevel($userid,$username,$classid,"template");//操作权限
	$temptext=RepPhpAspJspcode($temptext);
	$gid=(int)$_POST['gid'];
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set indextemp='".addslashes($temptext)."'");
	//刷新首页
	if($gid==$public_r['deftempid']||(!$public_r['deftempid']&&($gid==1||$gid==0)))
	{
		NewsBq($classid,$temptext,1,0);
	}
	if($sql)
	{
	    insert_dolog("gid=$gid");//操作日志
		printerror("EditPublicTempSuccess","template/EditPublicTemp.php?tname=indextemp&gid=$gid");
	}
	else
	{
		printerror("DbError","history.go(-1)");
	}
}

//替换目录值
function RepPathStr($path){
	$path=str_replace("\\","",$path);
	$path=str_replace("/","",$path);
	return $path;
}

//返回配置文件内容
function ReturnGetConfig($apath=""){
	$filename=ECMS_PATH."e/class/config.php";
	$text=ReadFiletext($filename);
	$r=explode("//-------SysSeting-------",$text);
	$retext=$r[0]."//-------SysSeting-------
?>";
	return $retext;
}

//生成配置文件
function GetConfig(){
	global $empire,$dbtbpre,$editor;
	if($editor==1)
	{
		$apath="../";
	}
	$r=$empire->fetch1("select * from {$dbtbpre}enewspublic limit 1");
	$tr=$empire->fetch1("select downsofttemp,onlinemovietemp,listpagetemp from ".GetTemptb("enewspubtemp")." limit 1");
	$filename=ECMS_PATH."e/class/config.php";
	$setting=ReturnGetConfig($apath);
	$setting.="<?
//------------e_public
\$public_r=array('sitename'=>'".addslashes($r[sitename])."',
'siteurl'=>'".addslashes($r[siteurl])."',
'newsurl'=>'".addslashes($r[newsurl])."',
'filetype'=>'".addslashes($r[filetype])."',
'filesize'=>".$r[filesize].",
'relistnum'=>".$r[relistnum].",
'renewsnum'=>".$r[renewsnum].",
'min_keyboard'=>".$r[min_keyboard].",
'max_keyboard'=>".$r[max_keyboard].",
'search_num'=>".$r[search_num].",
'search_pagenum'=>".$r[search_pagenum].",
'newslink'=>".$r[newslink].",
'search_color'=>'".addslashes($r[search_color])."',
'checked'=>".$r[checked].",
'pltime'=>".$r[pltime].",
'searchtime'=>".$r[searchtime].",
'loginnum'=>".$r[loginnum].",
'logintime'=>".$r[logintime].",
'addnews_ok'=>".$r[addnews_ok].",
'register_ok'=>".$r[register_ok].",
'indextype'=>'".addslashes($r[indextype])."',
'goodlencord'=>".$r[goodlencord].",
'goodtype'=>'".addslashes($r[goodtype])."',
'searchtype'=>'".addslashes($r[searchtype])."',
'exittime'=>".$r[exittime].",
'smalltextlen'=>".$r[smalltextlen].",
'defaultgroupid'=>".$r[defaultgroupid].",
'fileurl'=>'".addslashes($r[fileurl])."',
'install'=>".$r[install].",
'phpmode'=>".$r[phpmode].",
'searchsubnews'=>".$r[searchsubnews].",
'plsize'=>".$r[plsize].",
'plincludesize'=>".$r[plincludesize].",
'dorepnum'=>".$r[dorepnum].",
'loadtempnum'=>".$r[loadtempnum].",
'bakdbpath'=>'".addslashes($r[bakdbpath])."',
'bakdbzip'=>'".addslashes($r[bakdbzip])."',
'downpass'=>'".addslashes($r[downpass])."',
'dwwidth'=>'".addslashes($r[dwwidth])."',
'dwheight'=>'".addslashes($r[dwheight])."',
'down_num'=>".$r[down_num].",
'filechmod'=>".$r[filechmod].",
'loginkey_ok'=>".$r[loginkey_ok].",
'tbname'=>'".addslashes($r[tbname])."',
'limittype'=>".$r[limittype].",
'plkey_ok'=>".$r[plkey_ok].",
'redodown'=>".$r[redodown].",
'downsofttemp'=>'".addslashes(stripSlashes($tr[downsofttemp]))."',
'onlinemovietemp'=>'".addslashes(stripSlashes($tr[onlinemovietemp]))."',
'havefp'=>".$r[havefp].",
'fpnum'=>".$r[fpnum].",
'lctime'=>".$r[lctime].",
'candocode'=>".$r[candocode].",
'opennotcj'=>".$r[opennotcj].",
'listpagetemp'=>'".addslashes(stripSlashes($tr[listpagetemp]))."',
'reuserpagenum'=>".$r[reuserpagenum].",
'revotejsnum'=>".$r[revotejsnum].",
'readjsnum'=>".$r[readjsnum].",
'qaddtran'=>".$r[qaddtran].",
'qaddtransize'=>".$r[qaddtransize].",
'ebakthisdb'=>".$r[ebakthisdb].",
'delnewsnum'=>".$r[delnewsnum].",
'openclasspv'=>".$r[openclasspv].",
'openpagepv'=>".$r[openpagepv].",
'markpos'=>".$r[markpos].",
'markimg'=>'".addslashes($r[markimg])."',
'marktext'=>'".addslashes($r[marktext])."',
'markfontsize'=>'".addslashes($r[markfontsize])."',
'markfontcolor'=>'".addslashes($r[markfontcolor])."',
'markfont'=>'".addslashes($r[markfont])."',
'adminloginkey'=>".$r[adminloginkey].",
'php_outtime'=>".$r[php_outtime].",
'listpagefun'=>'".addslashes($r[listpagefun])."',
'textpagefun'=>'".addslashes($r[textpagefun])."',
'adfile'=>'".addslashes($r[adfile])."',
'notsaveurl'=>'".addslashes($r[notsaveurl])."',
'rssnum'=>".$r[rssnum].",
'rsssub'=>".$r[rsssub].",
'savetxtf'=>'".addslashes($r[savetxtf])."',
'isonlyf'=>'".addslashes($r[isonlyf])."',
'linkfields'=>'".addslashes($r[linkfields])."',
'checkboxf'=>'".addslashes($r[checkboxf])."',
'dorepdlevelnum'=>".$r[dorepdlevelnum].",
'listpagelistfun'=>'".addslashes($r[listpagelistfun])."',
'listpagelistnum'=>".$r[listpagelistnum].",
'infolinknum'=>".$r[infolinknum].",
'searchgroupid'=>".$r[searchgroupid].",
'opencopytext'=>".$r[opencopytext].",
'reuserjsnum'=>".$r[reuserjsnum].",
'reuserlistnum'=>".$r[reuserlistnum].",
'opentitleurl'=>".$r[opentitleurl].",
'searchtempvar'=>".$r[searchtempvar].",
'showinfolevel'=>".$r[showinfolevel].",
'navfh'=>'".addslashes($r[navfh])."',
'spicwidth'=>".$r[spicwidth].",
'spicheight'=>".$r[spicheight].",
'spickill'=>".$r[spickill].",
'jpgquality'=>".$r[jpgquality].",
'markpct'=>".$r[markpct].",
'redoview'=>".$r[redoview].",
'reggetfen'=>".$r[reggetfen].",
'regbooktime'=>".$r[regbooktime].",
'revotetime'=>".$r[revotetime].",
'fpath'=>".$r[fpath].",
'filepath'=>'".addslashes($r[filepath])."',
'nreclass'=>'".addslashes($r[nreclass])."',
'nreinfo'=>'".addslashes($r[nreinfo])."',
'nrejs'=>'".addslashes($r[nrejs])."',
'nottobq'=>'".addslashes($r[nottobq])."',
'defspacestyleid'=>".$r[defspacestyleid].",
'canposturl'=>'".addslashes($r[canposturl])."',
'openspace'=>".$r[openspace].",
'defadminstyle'=>".$r[defadminstyle].",
'realltime'=>".$r[realltime].",
'closeip'=>'".addslashes($r[closeip])."',
'openip'=>'".addslashes($r[openip])."',
'hopenip'=>'".addslashes($r[hopenip])."',
'plface'=>'".addslashes($r[plface])."',
'plfacenum'=>".$r[plfacenum].",
'textpagelistnum'=>".$r[textpagelistnum].",
'memberlistlevel'=>".$r[memberlistlevel].",
'ebakcanlistdb'=>".$r[ebakcanlistdb].",
'deftempid'=>".$r[deftempid].");
//------------e_public
?>";
	WriteFiletext_n($filename,$setting);
}

//刷新信息列表
function ReListHtml($classid,$enews=0){
	global $empire,$class_r,$dbtbpre;
	$classid=(int)$classid;
	if(!$classid)
	{
		printerror("NotChangeReClassid","history.go(-1)");
	}
	$r=$empire->fetch1("select classtempid,islist from {$dbtbpre}enewsclass where classid='$classid'");
	$ret_r=ReturnAddF($r,$class_r[$classid][modid],$userid,$username,2,2,0);//返回自定义字段
	if($class_r[$classid][islast])//终极栏目
	{
		ListHtml($classid,$ret_r,0);
	}
	else
	{
		if($r[islist])
		{
			ListHtml($classid,$ret_r,3);
		}
		else
		{
			NewsBq($classid,GetClassTemp($r['classtempid']),0,0);
		}
	}
	if($enews==1)//内部刷新
	{return "";}
	insert_dolog("");//操作日志
	printerror("ReClassidSuccess","history.go(-1)");
}

//刷新专题
function ReZtHtml($ztid){
	global $class_zr;
	$ztid=(int)$ztid;
	if(!$ztid)
	{
		printerror("NotChangeReZtid","history.go(-1)");
	}
	$classid=$class_zr[$ztid][classid];
	ListHtml($ztid,$ret_r[0],1);
	insert_dolog("");//操作日志
	printerror("ReZtidSuccess","history.go(-1)");
}

//刷新所有列表
function ReListHtml_all($start,$do,$from){
	global $empire,$public_r,$fun_r,$class_r,$dbtbpre;
	$start=(int)$start;
	$b=0;
	if($do=="all")
	{
		insert_dolog("");//操作日志
		printerror("ReClassidAllSuccess",$from);
    }
	elseif($do=="zt")//刷新专题
	{
		$zsql=$empire->query("select ztid,ztname,ztnum,listtempid,classid from {$dbtbpre}enewszt where ztid>$start order by ztid limit ".$public_r[relistnum]);
		while($z_r=$empire->fetch($zsql))
		{
			$b=1;
			ListHtml($z_r[ztid],$ret_r[0],1);
			$end_classid=$z_r[ztid];
		}
		if(empty($b))
		{
			echo $fun_r[ReZtListNewsSuccess]."<script>self.location.href='ecmschtml.php?enews=ReListHtml_all&start=0&do=all&from=$from';</script>";
			exit();
		}
		//echo $fun_r[OneReZtListNewsSuccess]."(ZtID:<font color=red><b>".$end_classid."</b></font>)<script>self.location.href='ecmschtml.php?enews=ReListHtml_all&start=$end_classid&do=zt&from=$from';</script>";
		echo"<meta http-equiv=\"refresh\" content=\"".$public_r['realltime'].";url=ecmschtml.php?enews=ReListHtml_all&start=$end_classid&do=zt&from=$from\">".$fun_r[OneReZtListNewsSuccess]."(ZtID:<font color=red><b>".$end_classid."</b></font>)";
		exit();
	}
	//栏目
	$sql=$empire->query("select classid,classtempid,islast,islist from {$dbtbpre}enewsclass where classid>$start and nreclass=0 order by classid limit ".$public_r[relistnum]);
	while($r=$empire->fetch($sql))
	{
		$ret_r=ReturnAddF($r,$class_r[$r[classid]][modid],$userid,$username,2,2,0);//返回字段
		$b=1;
		if(!$r[islast])//大栏目
		{
			if($r[islist])
			{
				ListHtml($r[classid],$ret_r,3);
			}
			else
			{
				NewsBq($r[classid],GetClassTemp($r['classtempid']),0,0);
			}
		}
		else//子栏目
		{
			ListHtml($r[classid],$ret_r,0);
		}
		$end_classid=$r[classid];
	}
	if(empty($b))
	{
		echo $fun_r[ReListNewsSuccess]."<script>self.location.href='ecmschtml.php?enews=ReListHtml_all&start=0&from=$from&do=zt';</script>";
		exit();
    }
	//echo $fun_r[OneReListNewsSuccess]."(ID:<font color=red><b>".$end_classid."</b></font>)<script>self.location.href='ecmschtml.php?enews=ReListHtml_all&start=$end_classid&do=class&from=$from';</script>";
	echo"<meta http-equiv=\"refresh\" content=\"".$public_r['realltime'].";url=ecmschtml.php?enews=ReListHtml_all&start=$end_classid&do=class&from=$from\">".$fun_r[OneReListNewsSuccess]."(ID:<font color=red><b>".$end_classid."</b></font>)";
	exit();
}

//刷新内容页面
function ReNewsHtml($start,$classid,$from,$retype,$startday,$endday,$startid,$endid,$tbname,$havehtml){
	global $empire,$public_r,$class_r,$fun_r,$dbtbpre;
	$tbname=RepPostVar($tbname);
	if(empty($tbname))
	{
		printerror("ErrorUrl","history.go(-1)");
    }
	$start=(int)$start;
	$classid=(int)$classid;
	//按ID刷新
	if($retype)
	{
		$startid=(int)$startid;
		$endid=(int)$endid;
		$add1=$endid?' and id>='.$startid.' and id<='.$endid:'';
    }
	else
	{
		$startday=RepPostVar($startday);
		$endday=RepPostVar($endday);
		$add1=$startday&&$endday?' and truetime>='.to_time($startday.' 00:00:00').' and truetime<='.to_time($endday.' 23:59:59'):'';
    }
	//按栏目刷新
	if($classid)
	{
		if(empty($class_r[$classid][islast]))//大栏目
		{
			$where=ReturnClass($class_r[$classid][sonclass]);
		}
		else//终极栏目
		{
			$where="classid='$classid'";
		}
		$add1.=' and ('.$where.')';
    }
	//不生成
	$add1.=ReturnNreInfoWhere();
	//是否重复生成
	if($havehtml!=1)
	{
		$add1.=' and havehtml=0';
	}
	$b=0;
	$sql=$empire->query("select * from {$dbtbpre}ecms_".$tbname." where id>$start".$add1." order by id limit ".$public_r[renewsnum]);
	while($r=$empire->fetch($sql))
	{
		$b=1;
		$ret_r=ReturnAddF($r,$class_r[$r[classid]][modid],$userid,$username,2,1,0);//返回自定义字段
		GetHtml($r,$ret_r);//生成信息文件
		$new_start=$r[id];
	}
	if(empty($b))
	{
		/*
		//验证是否全部刷新成功
		$rechecktablenum=(int)getcvar('rechecktablenum');
	    $rechecktablenum+=1;
		if($rechecktablenum>=getcvar('retablenum'))
		{
			$enews="ReNewsHtml";
	        //操作日志
	        insert_dolog("");
	        echo"<script>alert('".$fun_r[ReAllInfoSuccess]."');parent.location.href='$from';</script>";
			exit();
		}
		esetcookie("rechecktablenum",$rechecktablenum);
		*/
		echo "<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><center><b>".$tbname.$fun_r[ReTableIsOK]."!</b></center>";
		db_close();
		$empire=null;
		exit();
	}
	//echo "<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\">".$fun_r[OneReNewsHtmlSuccess]."(ID:<font color=red><b>".$new_start."</b></font>)<script>self.location.href='ecmschtml.php?enews=ReNewsHtml&tbname=$tbname&classid=$classid&start=$new_start&from=$from&retype=$retype&startday=$startday&endday=$endday&startid=$startid&endid=$endid&havehtml=$havehtml';</script>";
	echo"<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><meta http-equiv=\"refresh\" content=\"".$public_r['realltime'].";url=ecmschtml.php?enews=ReNewsHtml&tbname=$tbname&classid=$classid&start=$new_start&from=$from&retype=$retype&startday=$startday&endday=$endday&startid=$startid&endid=$endid&havehtml=$havehtml\">".$fun_r[OneReNewsHtmlSuccess]."(ID:<font color=red><b>".$new_start."</b></font>)";
	exit();
}

//刷新最新文章与热门文章
function ReHot_NewNews(){
	global $empire,$dbtbpre;
	$public_r=$empire->fetch1("select hotnum,newnum,sub_hot,sub_new,goodnum,sub_good,hotshowdate,newshowdate,goodshowdate,hotplnum,sub_hotpl,hotplshowdate,firstnum,sub_first,firstshowdate,jstempid from {$dbtbpre}enewspublic limit 1");
	$jstemptext=GetTheJstemp($public_r['jstempid']);//取得js模板
	GetNewsJs($classid,$public_r[newnum],$public_r[sub_new],$public_r[newshowdate],3,$jstemptext);
	GetNewsJs($classid,$public_r[hotnum],$public_r[sub_hot],$public_r[hotshowdate],4,$jstemptext);
	GetNewsJs($classid,$public_r[goodnum],$public_r[sub_good],$public_r[goodshowdate],5,$jstemptext);
	GetNewsJs($classid,$public_r[hotplnum],$public_r[sub_hotpl],$public_r[hotplshowdate],10,$jstemptext);
	GetNewsJs($classid,$public_r[firstnum],$public_r[sub_first],$public_r[firstshowdate],13,$jstemptext);
	insert_dolog("");//操作日志
	printerror("ReNewHotSuccess","history.go(-1)");
}

//刷新所有js
function ReAllNewsJs($start,$do,$from){
	global $empire,$public_r,$fun_r,$dbtbpre;
	$start=(int)$start;
	$line=$public_r[relistnum];
	$b=0;
	if($do=="all")
	{
		$pr=$empire->fetch1("select hotnum,newnum,sub_hot,sub_new,goodnum,sub_good,hotshowdate,newshowdate,goodshowdate,hotplnum,sub_hotpl,hotplshowdate,firstnum,sub_first,firstshowdate,jstempid from {$dbtbpre}enewspublic limit 1");
		$jstemptext=GetTheJstemp($pr['jstempid']);//js模板
		//刷新全部js
		GetNewsJs($classid,$pr[newnum],$pr[sub_new],$pr[newshowdate],3,$jstemptext);
		GetNewsJs($classid,$pr[hotnum],$pr[sub_hot],$pr[hotshowdate],4,$jstemptext);
		GetNewsJs($classid,$pr[goodnum],$pr[sub_good],$pr[goodshowdate],5,$jstemptext);
		GetNewsJs($classid,$pr[hotplnum],$pr[sub_hotpl],$pr[hotplshowdate],10,$jstemptext);
		GetNewsJs($classid,$pr[firstnum],$pr[sub_first],$pr[firstshowdate],13,$jstemptext);
		insert_dolog("");//操作日志
		printerror("ReAllJsSuccess",$from);
	}
	elseif($do=="zt")//刷新专题js
	{
		$from=urlencode($from);
		$sql=$empire->query("select ztid,newline,newshowdate,newstrlen,hotline,hotstrlen,hotshowdate,goodline,goodstrlen,goodshowdate,hotplline,hotplshowdate,hotplstrlen,firstline,firstshowdate,firststrlen,jstempid from {$dbtbpre}enewszt where ztid>$start and nrejs=0 order by ztid limit $line");
		while($r=$empire->fetch($sql))
		{
			$jstemptext=GetTheJstemp($r[jstempid]);//js模板
			$b=1;
			GetNewsJs($r[ztid],$r[newline],$r[newstrlen],$r[newshowdate],6,$jstemptext);
			GetNewsJs($r[ztid],$r[hotline],$r[hotstrlen],$r[hotshowdate],7,$jstemptext);
			GetNewsJs($r[ztid],$r[goodline],$r[goodstrlen],$r[goodshowdate],8,$jstemptext);
			GetNewsJs($r[ztid],$r[hotplline],$r[hotplstrlen],$r[hotplshowdate],11,$jstemptext);
			GetNewsJs($r[ztid],$r[firstline],$r[firststrlen],$r[firstshowdate],14,$jstemptext);
			$newstart=$r[ztid];
		}
		//刷新完毕
		if(empty($b))
		{
			echo $fun_r[ReZtNewsJsSuccess]."<script>self.location.href='ecmschtml.php?enews=ReAllNewsJs&do=all&start=0&from=$from';</script>";
			exit();
	    }
		//echo $fun_r[OneReZtNewsJsSuccess]."(ZtID:<font color=red><b>".$newstart."</b></font>)<script>self.location.href='ecmschtml.php?enews=ReAllNewsJs&do=zt&start=$newstart&from=$from';</script>";
		echo"<meta http-equiv=\"refresh\" content=\"".$public_r['realltime'].";url=ecmschtml.php?enews=ReAllNewsJs&do=zt&start=$newstart&from=$from\">".$fun_r[OneReZtNewsJsSuccess]."(ZtID:<font color=red><b>".$newstart."</b></font>)";
		exit();
	}
	else//刷新栏目js
	{
		$from=urlencode($from);
		$sql=$empire->query("select classid,newline,newshowdate,newstrlen,hotline,hotstrlen,hotshowdate,goodline,goodstrlen,goodshowdate,hotplline,hotplshowdate,hotplstrlen,firstline,firstshowdate,firststrlen,jstempid from {$dbtbpre}enewsclass where classid>$start and nrejs=0 and wburl='' order by classid limit $line");
		while($r=$empire->fetch($sql))
		{
			$jstemptext=GetTheJstemp($r[jstempid]);//js模板
			$b=1;
			GetNewsJs($r[classid],$r[newline],$r[newstrlen],$r[newshowdate],0,$jstemptext);
			GetNewsJs($r[classid],$r[hotline],$r[hotstrlen],$r[hotshowdate],1,$jstemptext);
			GetNewsJs($r[classid],$r[goodline],$r[goodstrlen],$r[goodshowdate],2,$jstemptext);
			GetNewsJs($r[classid],$r[hotplline],$r[hotplstrlen],$r[hotplshowdate],9,$jstemptext);
			GetNewsJs($r[classid],$r[firstline],$r[firststrlen],$r[firstshowdate],12,$jstemptext);
			$newstart=$r[classid];
		}
		//刷新完毕
		if(empty($b))
		{
			echo $fun_r[ReClassNewsJsSuccess]."<script>self.location.href='ecmschtml.php?enews=ReAllNewsJs&do=zt&start=0&from=$from';</script>";
			exit();
	    }
		//echo $fun_r[OneReClassNewsJsSuccess]."(ID:<font color=red><b>".$newstart."</b></font>)<script>self.location.href='ecmschtml.php?enews=ReAllNewsJs&do=class&start=$newstart&from=$from';</script>";
		echo"<meta http-equiv=\"refresh\" content=\"".$public_r['realltime'].";url=ecmschtml.php?enews=ReAllNewsJs&do=class&start=$newstart&from=$from\">".$fun_r[OneReClassNewsJsSuccess]."(ID:<font color=red><b>".$newstart."</b></font>)";
		exit();
	}
}

//刷新单个栏目
function ReSingleJs($classid,$doing=0){
	global $empire,$dbtbpre;
	$classid=(int)$classid;
	//刷新栏目
	if($doing==0)
	{
		$r=$empire->fetch1("select classid,newline,newshowdate,newstrlen,hotline,hotstrlen,hotshowdate,goodline,goodstrlen,goodshowdate,hotplline,hotplshowdate,hotplstrlen,firstline,firstshowdate,firststrlen,jstempid from {$dbtbpre}enewsclass where classid='$classid'");
		$jstemptext=GetTheJstemp($r[jstempid]);//js模板
		GetNewsJs($r[classid],$r[newline],$r[newstrlen],$r[newshowdate],0,$jstemptext);
		GetNewsJs($r[classid],$r[hotline],$r[hotstrlen],$r[hotshowdate],1,$jstemptext);
		GetNewsJs($r[classid],$r[goodline],$r[goodstrlen],$r[goodshowdate],2,$jstemptext);
		GetNewsJs($r[classid],$r[hotplline],$r[hotplstrlen],$r[hotplshowdate],9,$jstemptext);
		GetNewsJs($r[classid],$r[firstline],$r[firststrlen],$r[firstshowdate],12,$jstemptext);
	}
	//刷新专题js
	elseif($doing==1)
	{
		$r=$empire->fetch1("select ztid,newline,newshowdate,newstrlen,hotline,hotstrlen,hotshowdate,goodline,goodstrlen,goodshowdate,hotplline,hotplshowdate,hotplstrlen,firstline,firstshowdate,firststrlen,jstempid from {$dbtbpre}enewszt where ztid='$classid'");
		$jstemptext=GetTheJstemp($r[jstempid]);//js模板
		GetNewsJs($r[ztid],$r[newline],$r[newstrlen],$r[newshowdate],6,$jstemptext);
		GetNewsJs($r[ztid],$r[hotline],$r[hotstrlen],$r[hotshowdate],7,$jstemptext);
		GetNewsJs($r[ztid],$r[goodline],$r[goodstrlen],$r[goodshowdate],8,$jstemptext);
		GetNewsJs($r[ztid],$r[hotplline],$r[hotplstrlen],$r[hotplshowdate],11,$jstemptext);
		GetNewsJs($r[ztid],$r[firstline],$r[firststrlen],$r[firstshowdate],14,$jstemptext);
    }
	else
	{}
	insert_dolog("");//操作日志
	printerror("ReJsSuccess","history.go(-1)");
}

//生成js
function GetNewsJs($classid,$line,$sub,$showdate,$enews=0,$tempr){
	global $empire,$public_r,$class_r,$class_zr,$dbtbpre;
	if(empty($line))
	{
		$line=10;
	}
	if(empty($sub))
	{
		$sub=26;
	}
	//栏目
	if($enews==0||$enews==1||$enews==2||$enews==9||$enews==12||$enews==15)
	{
		if($class_r[$classid][islast])
		{
			$where="classid='$classid'";
		}
		else
		{
			$where=ReturnClass($class_r[$classid][sonclass]);
			if(empty($where))
			{$where="classid=0";}
		}
    }
	$allpath='../../d/js/js/';
	$ztpath='../../d/js/class/zt'.$classid.'_';
	$classpath='../../d/js/class/class'.$classid.'_';
	//栏目最新
	if($enews==0)
	{
	   $tbname=$class_r[$classid][tbname];
	   $query="(".$where.") and checked=1";
	   $order="newstime";
	   $newsjs=$classpath."newnews.js";
    }
	//栏目热门
	elseif($enews==1)
	{
	   $tbname=$class_r[$classid][tbname];
	   $query="(".$where.") and checked=1";
	   $order="onclick";
	   $newsjs=$classpath."hotnews.js";
    }
	//栏目推荐
	elseif($enews==2)
	{
	   $tbname=$class_r[$classid][tbname];
	   $query="(".$where.") and checked=1 and isgood=1";
	   $order="newstime";
	   $newsjs=$classpath."goodnews.js";
    }
	//各栏目评论排行
	elseif($enews==9)
	{
	   $tbname=$class_r[$classid][tbname];
	   $query="(".$where.") and checked=1";
	   $order="plnum";
	   $newsjs=$classpath."hotplnews.js";
    }
	//各栏目头条
	elseif($enews==12)
	{
		$tbname=$class_r[$classid][tbname];
		$query="(".$where.") and checked=1 and firsttitle=1";
		$order="newstime";
		$newsjs=$classpath."firstnews.js";
    }
	//所有最新
	elseif($enews==3)
	{
	   $tbname=$public_r['tbname'];
	   $query="checked=1";
	   $order="newstime";
	   $newsjs=$allpath."newnews.js";
    }
	//所有点击排行
	elseif($enews==4)
	{
	   $tbname=$public_r['tbname'];
	   $query="checked=1";
	   $order="onclick";
	   $newsjs=$allpath."hotnews.js";
    }
	//所有推荐
	elseif($enews==5)
	{
	   $tbname=$public_r['tbname'];
	   $query="isgood=1 and checked=1";
	   $order="newstime";
	   $newsjs=$allpath."goodnews.js";
    }
	//所有评论排行
	elseif($enews==10)
	{
	   $tbname=$public_r['tbname'];
	   $query="checked=1";
	   $order="plnum";
	   $newsjs=$allpath."hotplnews.js";
    }
	//所有头条
	elseif($enews==13)
	{
	   $tbname=$public_r['tbname'];
	   $query="firsttitle=1 and checked=1";
	   $order="newstime";
	   $newsjs=$allpath."firstnews.js";
    }
	//专题最新
	elseif($enews==6)
	{
	   $tbname=$class_zr[$classid][tbname];
	   $query="ztid like '%|".$classid."|%' and checked=1";
	   $order="newstime";
	   $newsjs=$ztpath."newnews.js";
    }
	//专题点击排行
	elseif($enews==7)
	{
	   $tbname=$class_zr[$classid][tbname];
	   $query="ztid like '%|".$classid."|%' and checked=1";
	   $order="onclick";
	   $newsjs=$ztpath."hotnews.js";
    }
	//专题推荐
	elseif($enews==8)
	{
	   $tbname=$class_zr[$classid][tbname];
	   $query="ztid like '%|".$classid."|%' and checked=1 and isgood=1";
	   $order="newstime";
	   $newsjs=$ztpath."goodnews.js";
    }
	//专题评论排行
	elseif($enews==11)
	{
	   $tbname=$class_zr[$classid][tbname];
	   $query="ztid like '%|".$classid."|%' and checked=1";
	   $order="plnum";
	   $newsjs=$ztpath."hotplnews.js";
    }
	//专题头条
	elseif($enews==14)
	{
	   $tbname=$class_zr[$classid][tbname];
	   $query="ztid like '%|".$classid."|%' and checked=1 and firsttitle=1";
	   $order="newstime";
	   $newsjs=$ztpath."firstnews.js";
    }
	$query="select id,newspath,title,filename,newstime,classid,titleurl,groupid,titlepic,titlefont from {$dbtbpre}ecms_".$tbname." where ".$query." order by istop desc,".$order." desc,id desc limit $line";
	$sql=$empire->query($query);
	//取得js模板
	$temp_r=explode("[!--empirenews.listtemp--]",$tempr[temptext]);
	while($r=$empire->fetch($sql))
	{
		if($showdate)//显示时间
		{
			$newstime=format_datetime($r[newstime],$tempr[showdate]);
	    }
		$r[title]=str_replace("\r\n","",$r[title]);
		$oldtitle=$r[title];
		$title=sub(stripSlashes($r[title]),0,$sub,false);
		$title=RepJsTemp($temp_r[1],$r,$title,$newstime,$oldtitle);
		$allnew.=$title;
	}
	$allnew="document.write(\"".$temp_r[0].addslashes($allnew).$temp_r[2]."\");";
	WriteFiletext_n($newsjs,$allnew);
}

//替换JS模板
function RepJsTemp($temptext,$r,$title,$newstime,$oldtitle){
	global $public_r,$class_r;
	$temptext=stripSlashes($temptext);
	$titlelink=sys_ReturnBqTitleLink($r);//标题链接
	$title=DoTitleFont($r[titlefont],$title);//标题加色
	$classurl=sys_ReturnBqClassname($r,9);//栏目链接
	$classname=$class_r[$r[classid]][bname]?$class_r[$r[classid]][bname]:$class_r[$r[classid]][classname];
	$temptext=str_replace("[!--titleurl--]",$titlelink,$temptext);
	$temptext=str_replace("[!--title--]",$title,$temptext);
	$temptext=str_replace("[!--writer--]",$r[writer],$temptext);
	$temptext=str_replace("[!--newstime--]",$newstime,$temptext);
	$temptext=str_replace("[!--id--]",$r[id],$temptext);
	$temptext=str_replace("[!--classid--]",$r[classid],$temptext);
	$temptext=str_replace("[!--classname--]",$classname,$temptext);
	$temptext=str_replace("[!--classurl--]",$classurl,$temptext);
	$temptext=str_replace("[!--oldtitle--]",$oldtitle,$temptext);
	//图片
	if(empty($r[titlepic]))
	{
		$r[titlepic]=$public_r[newsurl]."e/data/images/notimg.gif";
	}
	$temptext=str_replace("[!--titlepic--]",$r[titlepic],$temptext);
	return $temptext;
}

//远程保存忽略地址
function CheckNotSaveUrl($url){
	global $public_r;
	if(empty($public_r['notsaveurl']))
	{
		return 0;
    }
	$r=explode("\r\n",$public_r['notsaveurl']);
	$count=count($r);
	$re=0;
	for($i=0;$i<$count;$i++)
	{
		if(empty($r[$i]))
		{continue;}
		if(strstr($url,$r[$i]))
		{
			$re=1;
			break;
	    }
    }
	return $re;
}

//远程保存
function DoTranUrl($url,$classid){
	global $public_r,$class_r,$tranpicturetype,$tranflashtype,$mediaplayertype,$realplayertype,$addgethtmlpath;
	$url=trim($url);
	$url=str_replace(" ","%20",$url);
    $r[tran]=1;
	$r[url]=$url;
	$filetype=GetFiletype($url);//取得文件类型
	if(CheckSaveTranFiletype($filetype))
	{
		$r[tran]=0;
		return $r;
	}
	//是否已上传的文件
	$havetr=CheckNotSaveUrl($url);
	if($havetr)
	{
		$r[tran]=0;
		return $r;
	}
	$string=ReadFiletext($url);
	if(empty($string))//读取不了
	{
		$r[tran]=0;
		return $r;
	}
	$r[insertfile]=md5(uniqid(microtime()));
	$r[filename]=$r[insertfile].$filetype;
	$r[filepath]=FormatFilePath($classid,$mynewspath,0);
	$filepath=$r[filepath]?$r[filepath].'/':$r[filepath];
	//按栏目
	$fspath=ReturnFileSavePath($classid);
	$path=$addgethtmlpath."../../".$fspath['filepath'].$filepath;
	$r[url]=$fspath['fileurl'].$filepath.$r[filename];
	$r[savepath]=$path;
	$r[name]=$path."small".$r[insertfile];
	$path=$path.$r[filename];
	$r[yname]=$path;
	WriteFiletext_n($path,$string);
	$r[filesize]=@filesize($path);
	//返回类型
	if(strstr($tranflashtype,','.$filetype.','))
	{
		$r[type]=2;
	}
	elseif(strstr($tranpicturetype,','.$filetype.','))
	{
		$r[type]=1;
	}
	elseif(strstr($mediaplayertype,','.$filetype.',')||strstr($realplayertype,','.$filetype.','))//多媒体
	{
		$r[type]=3;
	}
	else
	{
		$r[type]=0;
	}
	return $r;
}

//替换图片标签
function RepImg($text,$copyflash){
	global $saveurlimgclearurl;
	$exp1="[--copyimg--]";
	$exp2="[/--copyimg--]";
	//去掉图片链接
	if($saveurlimgclearurl==1)
	{
		$zz2="/\<(a|A) (.*?)(href|Href)=('|\"|\\\\\"|)(.+?)><(img|IMG) (.*?)(src|SRC)=('|\"|\\\\\"|)(.+?)(.jpg|.JPG|.gif|.GIF|.png|.PNG|.bmp|.BMP|.jpeg|.JPEG)(.*?)><\/(a|A)>/is";
		$text=preg_replace($zz2,"<\\6 \\7\\8=\\9\\10\\11\\12>",$text);
	}
	$zz1="/\<(img|IMG) (.*?)(src|SRC)=('|\"|\\\\\"|)(.+?)(.jpg|.JPG|.gif|.GIF|.png|.PNG|.bmp|.BMP|.jpeg|.JPEG)(.*?)>/is";
	$text=preg_replace($zz1,"<\\1 \\2\\3=\\4".$exp1."\\5\\6".$exp2."\\7>",$text);
	return $text;
}

//替换flash标签
function RepFlash($text,$copyflash){
	$exp1="[--copyimg--]";
	$exp2="[/--copyimg--]";
	//去掉flash多余链接
	$zz2="/\<(embed|EMBED) (.*?)(src|SRC)=('|\"|\\\\\"|)(.+?)(.swf|.SWF)(.*?)>(.*?)<\/(embed|EMBED)>/is";
	$text=preg_replace($zz2,"",$text);
	$zz3="/\<(param|PARAM) (name|NAME)=\"(Src|src|SRC)\" (.*?)(value|VALUE)=('|\"|\\\\\"|)(.+?)(.swf|.SWF)(.*?)>/is";
	$text=preg_replace($zz3,"",$text);

	$zz1="/\<(param|PARAM) (.*?)(name|NAME)=\"(movie|MOVIE)\" (.*?)(value|VALUE)=('|\"|\\\\\"|)(.+?)(.swf|.SWF)(.*?)>/is";
	$text=preg_replace($zz1,"<\\1 \\2\\3=\"\\4\" \\5\\6=\\7".$exp1."\\8\\9".$exp2."\\10>",$text);
	return $text;
}

//截取图片
function CopyImg($text,$copyimg,$copyflash,$classid,$qz,$username,$theid,$cjid,$mark){
	global $empire,$public_r,$cjnewsurl,$navtheid,$dbtbpre;
	if(empty($text))
	{return "";}
	if($copyimg)
	{
		$text=RepImg($text,$copyflash);
	}
	if($copyflash)
	{$text=RepFlash($text,$copyflash);}
	$exp1="[--copyimg--]";
	$exp2="[/--copyimg--]";
	$r=explode($exp1,$text);
	for($i=1;$i<count($r);$i++)
	{
		$r1=explode($exp2,$r[$i]);
		if(strstr($r1[0],"http://")||strstr($r1[0],"https://"))
	    {
			$dourl=$r1[0];
		}
		else
	    {
			//是否是本地址
			if(!strstr($r1[0],"/")&&$cjnewsurl)
			{
				$fileqz_r=GetPageurlQz($cjnewsurl);
				$fileqz=$fileqz_r['selfqz'];
				$dourl=$fileqz.$r1[0];
			}
			else
			{
				$dourl=$qz.$r1[0];
			}
		}
		$return_r=DoTranUrl($dourl,$classid);
		$text=str_replace($exp1.$r1[0].$exp2,$return_r[url],$text);
		if($return_r[tran])
	    {
			//记录数据库
			$filetime=date("Y-m-d H:i:s");
			//变量处理
			$return_r[filesize]=(int)$return_r[filesize];
			$classid=(int)$classid;
			$return_r[type]=(int)$return_r[type];
			$theid=(int)$theid;
			$cjid=(int)$cjid;
			$sql=$empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,id,cjid,onclick,fpath) values('$return_r[filename]',$return_r[filesize],'$username','$return_r[filepath]','$filetime',$classid,'[URL]".$return_r[filename]."',$return_r[type],$theid,$cjid,0,'$public_r[fpath]');");
			//加水
			if($mark&&$return_r[type]==1)
			{
				GetMyMarkImg($return_r['yname']);
			}
        }
	}
	return $text;
}

//上传文件
function DoTranFile($file,$file_name,$file_type,$file_size,$classid){
	global $public_r,$class_r,$addgethtmlpath,$doetran;
	$filetype=GetFiletype($file_name);//取得文件类型
	$r[insertfile]=md5(uniqid(microtime()));
	$r[filename]=$r[insertfile].$filetype;
	$r[filepath]=FormatFilePath($classid,$mynewspath,0);//按日期存放文件
	$filepath=$r[filepath]?$r[filepath].'/':$r[filepath];
	$r[tran]=1;
	//按栏目
	$fspath=ReturnFileSavePath($classid);
	$path1=$addgethtmlpath."../../".$fspath['filepath'].$filepath;
	$r[url]=$fspath['fileurl'].$filepath.$r[filename];
	$r[savepath]=$path1;
	$r[name]=$path1."small".$r[insertfile];
	$path=$path1.$r[filename];
	$r[yname]=$path;
	//文件类型
	if(CheckSaveTranFiletype($filetype))
	{
		if($doetran)
		{
			$r[tran]=0;
			return $r;
		}
		else
		{
			printerror("TranFail","history.go(-1)");
		}
	}
	//上传文件
	$cp=@move_uploaded_file($file,$path);
	if(empty($cp))
	{
		if($doetran)
		{
			$r[tran]=0;
			return $r;
		}
		else
		{
			printerror("TranFail","history.go(-1)");
		}
	}
	DoChmodFile($path);
	$r[filesize]=$file_size;
	return $r;
}

//生成缩略图
function GetMySmallImg($classid,$no,$insertfile,$filepath,$yname,$maxwidth,$maxheight,$name,$id,$cjid,$userid,$username){
	global $empire,$dbtbpre,$public_r;
	if(empty($yname))
	{
		return "";
    }
	$no="[s]".$no;
	$filer=ResizeImage($yname,$name,$maxwidth,$maxheight,$public_r['spickill']);
	if($filer['file'])
	{
		$insertfile="small".$insertfile.$filer['filetype'];
		$filesize=@filesize($filer['file']);
		//写入数据库
		$filetime=date("Y-m-d H:i:s");
		//变量处理
		$filesize=(int)$filesize;
		$classid=(int)$classid;
		$id=(int)$id;
		$cjid=(int)$cjid;
		$sql=$empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,id,cjid,onclick,fpath) values('$insertfile',$filesize,'$username','$filepath','$filetime',$classid,'$no',1,$id,$cjid,0,'$public_r[fpath]');");
    }
	return $filer;
}

//图片加水印
function GetMyMarkImg($groundImage){
	global $public_r;
	if(empty($groundImage))
	{
		return "";
    }
	imageWaterMark($groundImage,$public_r['markpos'],$public_r['markimg'],$public_r['marktext'],$public_r['markfontsize'],$public_r['markfontcolor'],$public_r['markfont'],$public_r['markpct'],$public_r['jpgquality']);
}

//验证图片是否合法
function eTranMorePicCheck($url,$filesize){
	global $public_r,$tranpicturetype;
	$filetype=GetFiletype($url);//扩展名
	//如果是.php文件
	if(CheckSaveTranFiletype($filetype))
	{
		return 0;
	}
	if(!strstr($public_r['filetype'],"|".$filetype."|"))
	{
		return 0;
	}
	if($filesize>$public_r['filesize']*1024)
	{
		return 0;
	}
	//扩展名是否合法
	if(!strstr($tranpicturetype,','.$filetype.','))
	{
		return 0;
	}
	return 1;
}

//返回图片格式
function eTranMorePicGs($bimgurl,$imgurl,$r){
	if($r['width'])
	{
		$width=" width=".$r['width'];
	}
	if($r['height'])
	{
		$height=" height=".$r['height'];
	}
	$pic="<a href='".$bimgurl."' target='_blank'><img src='".$imgurl."' border=".$r['imgborder'].$width.$height."></a>";
	return $pic;
}

//返回表格格式
function eTranMoreTbGs($r){
	if($r['tbcolor'])
	{
		$tbcolor="  bgcolor='".$r['tbcolor']."'";
	}
	if($r['tbbordercolor'])
	{
		$tbbordercolor=" bordercolor='".$r['tbbordercolor']."'";
	}
	if($r['tbsp'])
	{
		$tbsp=" cellspacing='".$r['tbsp']."'";
	}
	if($r['tbpa'])
	{
		$tbpa=" cellpadding='".$r['tbpa']."'";
	}
	if($r['tbwidth'])
	{
		$tbwidth=" width='".$r['tbwidth'].$r['tbwidthdw']."'";
	}
	$table="<table".$tbwidth." border='".$r['tbborder']."'".$tbpa.$tbsp.$tbbordercolor.$tbcolor." align='".$r['tbalign']."'>";
	return $table;
}

//编辑器上传多图片
function eTranMorePic($file,$file_name,$file_type,$file_size,$add,$userid,$username){
	global $empire,$public_r,$dbtbpre,$fun_r;
	//导入gd处理文件
	if($add['getsmall']||$add['getmark'])
	{
		@include(ECMS_PATH."e/class/gd.php");
	}
	$j=0;
	$line=(int)$add['line'];
	if($line==0)
	{
		$line=1;
    }
	//远程保存
	if($add['saveurl'])
	{
		$url_r=explode("\r\n",$add['saveurl']);
		$count=count($url_r);
		for($i=0;$i<$count;$i++)
		{
			if(empty($url_r[$i]))
			{continue;}
			//验证图片
			$check=eTranMorePicCheck($url_r[$i],0);
			if($check==0)
			{continue;}
			//开始上传
			$r=DoTranUrl($url_r[$i],$add['classid']);
			if(empty($r[tran]))
		    {
				continue;
			}
			$imgurl=$r['url'];
			$bimgurl=$r['url'];
			//写入数据库
			$r[filesize]=(int)$r[filesize];
			$add[classid]=(int)$add[classid];
			$add[type]=(int)$add[type];
			$add[filepass]=(int)$add[filepass];
			$filetime=date("Y-m-d H:i:s");
			$sql=$empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,id,cjid,onclick,fpath) values('$r[filename]',$r[filesize],'$username','$r[filepath]','$filetime',$add[classid],'$r[filename]',$add[type],$add[filepass],$add[filepass],0,'$public_r[fpath]');");
			//缩略图
			if($add['getsmall'])
			{
				$sfiler=GetMySmallImg($add['classid'],$r[filename],$r[insertfile],$r[filepath],$r[yname],$add[swidth],$add[sheight],$r[name],$add['filepass'],$add['filepass'],$userid,$username);
				$imgurl=str_replace("/".$r[filename],"/small".$r[insertfile].$sfiler['filetype'],$r[url]);
			}
			//水印
			if($add['getmark'])
			{
				GetMyMarkImg($r['yname']);
			}
			//开始输出字符
			$j++;
			//分页
			if($add['exptype']==1)
			{
				$classtext.="<p align='".$add['align']."'>".eTranMorePicGs($bimgurl,$imgurl,$add)."</p>";
				if($j%$line==0)
				{
					$classtext.="[!--empirenews.page--]";
				}
			}
			//表格
			else
			{
				if(($j-1)%$line==0||$j==1)
				{$classtext.="<tr>";}
				$classtext.="<td align=".$add['align'].">".eTranMorePicGs($bimgurl,$imgurl,$add)."</td>";
				if($j%$line==0)
				{$classtext.="</tr>";}
			}
		}
		//表格
		if($add['exptype']==0)
		{
			if($j<>0)
			{
		      $table=eTranMoreTbGs($add);
			  $table1="</table>";
              $ys=$line-$j%$line;
			  $p=0;
              for($k=0;$k<$ys&&$ys!=$line;$k++)
			  {
				$p=1;
				$classtext.="<td></td>";
              }
			  if($p==1)
			  {
				 $classtext.="</tr>";
			  }
			}
			$classtext=$table.$classtext.$table1;
		}
		//分页
		else
		{
			if($j%$line==0)
			{
				$classtext=substr($classtext,0,strlen($classtext)-22);
			}
		}
	}
	//本地上传
	else
	{
		$count=count($file_name);
		if($count==0)
		{
			printerror("MustChangeTranOneFile","history.go(-1)");
	    }
		$GLOBALS['doetran']=1;
		for($i=0;$i<$count;$i++)
		{
			if(empty($file_name[$i]))
			{
				continue;
			}
			//验证图片
			$check=eTranMorePicCheck($file_name[$i],$file_size[$i]);
			if($check==0)
			{
				continue;
			}
			//上传
			$r=DoTranFile($file[$i],$file_name[$i],$file_type[$i],$file_size[$i],$add['classid']);
			if(empty($r[tran]))
		    {
				continue;
			}
			$imgurl=$r['url'];
			$bimgurl=$r['url'];
			//写入数据库
			$r[filesize]=(int)$r[filesize];
			$add[classid]=(int)$add[classid];
			$add[type]=(int)$add[type];
			$add[filepass]=(int)$add[filepass];
			$filetime=date("Y-m-d H:i:s");
			$sql=$empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,id,cjid,onclick,fpath) values('$r[filename]',$r[filesize],'$username','$r[filepath]','$filetime',$add[classid],'$r[filename]',$add[type],$add[filepass],$add[filepass],0,'$public_r[fpath]');");
			//缩略图
			if($add['getsmall'])
			{
				$sfiler=GetMySmallImg($add['classid'],$r[filename],$r[insertfile],$r[filepath],$r[yname],$add[swidth],$add[sheight],$r[name],$add['filepass'],$add['filepass'],$userid,$username);
				$imgurl=str_replace("/".$r[filename],"/small".$r[insertfile].$sfiler['filetype'],$r[url]);
			}
			//水印
			if($add['getmark'])
			{
				GetMyMarkImg($r['yname']);
			}
			//开始输出字符
			$j++;
			//分页
			if($add['exptype']==1)
			{
				$classtext.="<p align=".$add['align'].">".eTranMorePicGs($bimgurl,$imgurl,$add)."</p>";
				if($j%$line==0)
				{
					$classtext.="[!--empirenews.page--]";
				}
			}
			//表格
			else
			{
				if(($j-1)%$line==0||$j==1)
				{$classtext.="<tr>";}
				$classtext.="<td align=".$add['align'].">".eTranMorePicGs($bimgurl,$imgurl,$add)."</td>";
				if($j%$line==0)
				{$classtext.="</tr>";}
			}
		}
		//表格
		if($add['exptype']==0)
		{
			if($j<>0)
			{
		      $table=eTranMoreTbGs($add);
			  $table1="</table>";
              $ys=$line-$j%$line;
			  $p=0;
              for($k=0;$k<$ys&&$ys!=$line;$k++)
			  {
			   $p=1;
               $classtext.="<td></td>";
               }
			   if($p==1)
				{
				   $classtext.="</tr>";
			   }
			}
			$classtext=$table.$classtext.$table1;
		}
		//分页
		else
		{
			if($j%$line==0)
			{
			$classtext=substr($classtext,0,strlen($classtext)-22);
			}
		}
	}
	echo $fun_r['TranFileSuccess']."<script>opener.DoFile(\"".$classtext."\");window.close();</script>";
	db_close();
	exit();
}

//批量加水印/缩略图
function DoMarkSmallPic($add,$userid,$username){
	global $empire,$class_r,$dbtbpre;
	//导入gd处理文件
	if($add['getsmall']||$add['getmark'])
	{
		@include(ECMS_PATH."e/class/gd.php");
	}
	else
	{
		printerror("EmptyDopicFileid","history.go(-1)");
	}
	$fileid=$add['fileid'];
	$count=count($fileid);
	if($count==0)
	{
		printerror("EmptyDopicFileid","history.go(-1)");
	}
	for($i=0;$i<$count;$i++)
	{
		$fileid[$i]=intval($fileid[$i]);
		$r=$empire->fetch1("select classid,filename,path,no,fpath from {$dbtbpre}enewsfile where fileid='$fileid[$i]'");
		$rpath=$r['path']?$r['path'].'/':$r['path'];
		$fspath=ReturnFileSavePath($r[classid],$r[fpath]);
		$path="../../".$fspath['filepath'].$rpath;
		$yname=$path.$r[filename];
		//缩略图
		if($add['getsmall'])
		{
			$filetype=GetFiletype($r[filename]);
			$insertfile=substr($r[filename],0,strlen($r[filename])-strlen($filetype));
			$name=$path."small".$insertfile;
			GetMySmallImg($add['classid'],$r[no],$insertfile,$r[path],$yname,$add[width],$add[height],$name,$add['filepass'],$add['filepass'],$userid,$username);
		}
		//水印
		if($add['getmark'])
		{
			GetMyMarkImg($yname);
		}
	}
	printerror("DoMarkSmallPicSuccess",$_SERVER['HTTP_REFERER']);
}

//上传多附件
function TranMoreFile($file,$file_name,$file_type,$file_size,$no,$type,$userid,$username){
	global $empire,$public_r,$dbtbpre;
	$count=count($file_name);
	if(empty($count))
	{
		printerror("MustChangeTranOneFile","history.go(-1)");
    }
	//操作权限
	CheckLevel($userid,$username,$classid,"file");
	$type=(int)$type;
	for($i=0;$i<$count;$i++)
	{
		if(empty($file_name[$i]))
		{
			continue;
		}
		//取得文件类型
		$filetype=GetFiletype($file_name[$i]);
		//如果是.php文件
		if(CheckSaveTranFiletype($filetype))
		{continue;}
	    $type_r=explode("|".$filetype."|",$public_r['filetype']);
	    if(count($type_r)<2)
		{continue;}
		if($file_size[$i]>$public_r['filesize']*1024)
		{continue;}
		//上传
		$r=DoTranFile($file[$i],$file_name[$i],$file_type[$i],$file_size[$i],$classid);
		//写入数据库
		$r[filesize]=(int)$r[filesize];
		$classid=(int)$classid;
		$filetime=date("Y-m-d H:i:s");
		if(empty($no[$i]))
		{$no[$i]=$r[filename];}
		$sql=$empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,onclick,id,cjid,fpath) values('$r[filename]',$r[filesize],'$username','$r[filepath]','$filetime',$classid,'$no[$i]',$type,0,0,0,'$public_r[fpath]');");
	}
	insert_dolog("");//操作日志
	printerror("TranMoreFileSuccess","file/TranMoreFile.php");
}

//插入图片
function EditorSetTranPic($picurl,$smallpic,$add){
	$imgstr="<img src='$picurl'";
	if($add[pic_autosize])
	{
		$imgstr.=" onload='autosimg(this);' onmousewheel='return zoomimg(this);'";
	}
	if($add[pic_height])
	{
		$imgstr.=" height='$add[pic_height]'";
	}
	if($add[pic_width])
	{
		$imgstr.=" width='$add[pic_width]'";
	}
	$imgstr.=" border='$add[pic_border]'";
	if($add[pic_alt])
	{
		$imgstr.=" alt='$add[pic_alt]'";
	}
	if($add[pic_vspace])
	{
		$imgstr.=" vspace='$add[pic_vspace]'";
	}
	if($add[pic_hspace])
	{
		$imgstr.=" hspace='$add[pic_hspace]'";
	}
	if($add[pic_align])
	{
		$imgstr.=" align='$add[pic_align]'";
	}
	if(empty($add[pic_link]))
	{
		$add[pic_link]=$picurl;
	}
	$imgstr="<a href='$add[pic_link]' target='$add[pic_linktarget]'>".$imgstr."></a>";
	if($add[pic_say])
	{
		$imgstr.="<br><span style='line-height=18pt'>".htmlspecialchars($add[pic_say])."</span>";
	}
	if($add[pic_align]=='center')
	{
		$imgstr='<center>'.$imgstr.'</center>';
	}
	return $imgstr;
}

//上传文件
function TranFile($file,$file_name,$file_type,$file_size,$tranurl,$no,$classid,$type,$post,$userid,$username){
	global $empire,$public_r,$loginrnd,$dbtbpre,$tranpicturetype,$tranflashtype,$mediaplayertype,$realplayertype;
	if(!$no)
	{
		$no=$file_name;
	}
	//是否为空
	if(!$file_name)
	{
		if(empty($tranurl)||$tranurl=="http://")
		{
			printerror("EmptyHttp","history.go(-1)");
		}
		$filetype=GetFiletype($tranurl);//取得文件类型
		$file_size=0;
    }
	else
	{
		$filetype=GetFiletype($file_name);//取得文件类型
	}
	//如果是.php文件
	if(CheckSaveTranFiletype($filetype))
	{
		printerror("TranPHP","history.go(-1)");
	}
	$type_r=explode("|".$filetype."|",$public_r['filetype']);
	if(count($type_r)<2)
	{
		printerror("TranFiletypFail","history.go(-1)");
	}
	if($file_size>$public_r['filesize']*1024)
	{
		printerror("TranFilesizeFail","history.go(-1)");
	}
	if($type==1)//上传图片
	{
		if(!strstr($tranpicturetype,','.$filetype.','))
		{
			printerror("NotTranImg","history.go(-1)");
		}
	}
	elseif($type==2)//上传flash
	{
		if(!strstr($tranflashtype,','.$filetype.','))
		{
			printerror("NotTranFlash","history.go(-1)");
		}
	}
	elseif($type==3)//上传多媒体
	{}
	else//上传附件
	{}
	//远程保存
	if(empty($file_name))
	{
		$r=DoTranUrl($tranurl,$classid);
		if(empty($r[tran]))
		{
			printerror("TranHttpFail","history.go(-1)");
		}
	}
	//本地上传
	else
	{
		$r=DoTranFile($file,$file_name,$file_type,$file_size,$classid);
	}
	if(!$no)
	{
		$no=$r[filename];
	}
	//写入数据库
	$r[filesize]=(int)$r[filesize];
	$classid=(int)$classid;
	$post[filepass]=(int)$post[filepass];
	$type=(int)$type;
	$filetime=date("Y-m-d H:i:s");
	$sql=$empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,id,cjid,fpath) values('$r[filename]',$r[filesize],'$username','$r[filepath]','$filetime',$classid,'$no',$type,$post[filepass],$post[filepass],'$public_r[fpath]');");
	$fileid=$empire->lastid();
	//导入gd.php文件
	if($type==1&&($post['getsmall']||$post['getmark']))
	{
		@include(ECMS_PATH."e/class/gd.php");
	}
	//缩略图
	if($type==1&&$post['getsmall'])
	{
		GetMySmallImg($classid,$no,$r[insertfile],$r[filepath],$r[yname],$post[width],$post[height],$r[name],$post['filepass'],$post['filepass'],$userid,$username);
	}
	//水印
	if($type==1&&$post['getmark'])
	{
		GetMyMarkImg($r['yname']);
	}
	if($sql)
	{
		if($post['tranfrom']==1)//编辑器上传
		{
			$imgstr=EditorSetTranPic($r[url],$r[url],$post);
			echo"<script>window.opener.DoFile(\"".$imgstr."\");window.close();</script>";
			db_close();
			exit();
		}
		echo"<script>parent.location.reload();</script>";
		db_close();
		exit();
	}
	else
	{
		printerror("InTranRecordFail","history.go(-1)");
	}
}

//删除附件
function DoDelFile($r){
	global $class_r,$addgethtmlpath;
	$path=$r['path']?$r['path'].'/':$r['path'];
	$fspath=ReturnFileSavePath($r[classid],$r[fpath]);
	$delfile=$addgethtmlpath."../../".$fspath['filepath'].$path.$r['filename'];
	$del=DelFiletext($delfile);
}

//写入日志
function insert_log($username,$password,$status,$loginip,$loginauth){
	global $empire,$do_theloginlog,$dbtbpre;
	if($do_theloginlog)
	{
		return "";
	}
	$password=RepPostVar($password);
	$loginauth=RepPostVar($loginauth);
	if($password)
	{
		$password=preg_replace("/^(.{".round(strlen($password) / 4)."})(.+?)(.{".round(strlen($password) / 6)."})$/s", "\\1***\\3", $password);
	}
	$username=RepPostVar($username);
	$logintime=date("Y-m-d H:i:s");
	$sql=$empire->query("insert into {$dbtbpre}enewslog(username,loginip,logintime,status,password,loginauth) values('$username','$loginip','$logintime','$status','$password','$loginauth');");
}

//写入操作日志
function insert_dolog($doing){
	global $empire,$enews,$phome,$logininid,$loginin,$do_thedolog,$dbtbpre;
	if($do_thedolog)
	{
		return "";
	}
	if(empty($doing))
	{$doing="---";}
	$doing=addslashes(stripSlashes($doing));
	//ip
	$logip=egetip();
	$logtime=date("Y-m-d H:i:s");
	if(empty($enews))
	{$enews=$phome;}
	$enews=RepPostVar($enews);
	$sql=$empire->query("insert into {$dbtbpre}enewsdolog(username,logip,logtime,enews,doing) values('$loginin','$logip','$logtime','$enews','$doing');");
}

//替换模板文件
function ReplaceStemp($temptext,$class,$url){
	global $public_r;
	$temptext=str_replace("[!--bgcolor--]",$public_r[search_color],$temptext);
	$temptext=str_replace("[!--class--]",$class,$temptext);
	$temptext=str_replace("[!--newsurl--]",$public_r[newsurl],$temptext);
	//热门文章
	$temptext=str_replace("[!--hotnews--]","<script src=".$public_r[newsurl]."d/js/js/hotnews.js></script>",$temptext);
	//点击排行
	$temptext=str_replace("[!--newnews--]","<script src=".$public_r[newsurl]."d/js/js/newnews.js></script>",$temptext);
	//推荐
	$temptext=str_replace("[!--goodnews--]","<script src=".$public_r[newsurl]."d/js/js/goodnews.js></script>",$temptext);
	//评论排行
	$temptext=str_replace("[!--hotplnews--]","<script src=".$public_r[newsurl]."d/js/js/hotplnews.js></script>",$temptext);
	//导行条
	$temptext=str_replace("[!--url--]",$url,$temptext);
	return $temptext;
}

//生成搜索文件
function GetSearch($mid=0){
	global $empire,$public_r,$fun_r,$dbtbpre;
	//取得模板
	$tr=$empire->fetch1("select searchtemp,searchjstemp,searchjstemp1 from ".GetTemptb("enewspubtemp")." limit 1");
	//返回栏目搜索
	$fcfile="../data/fc/ListEnews.php";
	$fcjsfile="../data/fc/cmsclass.js";
	if(file_exists($fcjsfile)&&file_exists($fcfile))
	{
		$options=GetFcfiletext($fcjsfile);
	}
	else
	{
		$options=ShowClass_AddClass("","n",0,"|-",0,1);
	}
	//$options="<script src=".$public_r[newsurl]."e/data/fc/searchclass.js></script>";
	$functions="function search_check(obj){if(obj.keyboard.value.length==0){alert('".$fun_r['EmptyKey']."');return false;}return true;}";
	//横向搜索
	$searchjstemp=ReplaceStemp($tr[searchjstemp],$options,$url);
	$text2=$functions."document.write(\"".$searchjstemp."\");";
	//纵向搜索
	$searchjstemp1=ReplaceStemp($tr[searchjstemp1],$options,$url);
	$text3.=$functions."document.write(\"".$searchjstemp1."\");";
	//高级搜索
	$url="<a href=".$public_r[newsurl].">".$fun_r['index']."</a>&nbsp;>&nbsp;<a href=../search>".$fun_r['adsearch']."</a>&nbsp;>";//导航栏
	$tr[searchtemp]=ReplaceTempvar($tr[searchtemp]);//公共模板变量
	$tr[searchtemp]=str_replace("[!--pagetitle--]",$fun_r['adsearch'],$tr[searchtemp]);
	$tr[searchtemp]=str_replace("[!--news.url--]",$public_r['newsurl'],$tr[searchtemp]);
	//搜索模板替换
	$dbsearchtemp=ReplaceStemp($tr[searchtemp],$options,$url);
	$text4=$dbsearchtemp;
	//增加信息栏目
	if($mid)
	{
		$options1=ShowClass_AddClass("","n",0,"|-",$mid,2);
		$addnews_class="document.write(\"".addslashes($options1)."\");";
		$filename3="../../d/js/js/addinfo".$mid.".js";
		WriteFiletext_n($filename3,$addnews_class);
    }
	$filename="../../d/js/js/search_news1.js";
	WriteFiletext_n($filename,$text2);
	$filename1="../../d/js/js/search_news2.js";
	WriteFiletext_n($filename1,$text3);
	$filename2="../../search/index".$public_r[searchtype];
	WriteFiletext($filename2,$text4);
}

//替换搜索结果变量
function RepSearchRtemp($temptext,$url){
	global $public_r;
	//热门文章
	$temptext=str_replace("[!--hotnews--]","<script src=".$public_r[newsurl]."d/js/js/hotnews.js></script>",$temptext);
	//点击排行
	$temptext=str_replace("[!--newnews--]","<script src=".$public_r[newsurl]."d/js/js/newnews.js></script>",$temptext);
	//推荐
	$temptext=str_replace("[!--goodnews--]","<script src=".$public_r[newsurl]."d/js/js/goodnews.js></script>",$temptext);
	//评论排行
	$temptext=str_replace("[!--hotplnews--]","<script src=".$public_r[newsurl]."d/js/js/hotplnews.js></script>",$temptext);
	//分页
	$temptext=str_replace("[!--listpage--]","<?=\$listpage?>",$temptext);
	//关键字
	$temptext=str_replace("[!--keyboard--]","<?=\$keyboard?>",$temptext);
	//总记录数
	$temptext=str_replace("[!--num--]","<?=\$num?>",$temptext);
	//导行条
	$temptext=str_replace("[!--url--]",$url,$temptext);
	$temptext=str_replace("[!--newsurl--]",$public_r[newsurl],$temptext);
	return $temptext;
}

//生成搜索结果文件
function GetSearchResult(){
	global $empire,$public_r,$fun_r,$dbtbpre;
	/*
	$t_filename="../data/template/searchtemp.php";
	$filename="../search/result/index.php";
	$searchtemp=ReadFiletext($t_filename);
	//导行栏
	$url="<a href=".$public_r[newsurl].">".$fun_r['index']."</a>&nbsp;>&nbsp;<a href=".$public_r[newsurl]."search>".$fun_r['adsearch']."</a>&nbsp;>&nbsp;".$fun_r['SearchResult']."&nbsp;>";
	//取得列表模板
	$sr=$empire->fetch1("select searchresulttemp from {$dbtbpre}enewspublic limit 1");
    $sr[searchresulttemp]=RepSearchRtemp($sr[searchresulttemp],$url);
	$searchtemp=str_replace("<!--empire.listtemp.subnews-->",$public_r[searchsubnews],$searchtemp);
	$listtemp_r=explode("[!--empirenews.listtemp--]",$sr[searchresulttemp]);
	$searchtemp=str_replace("<!--empire.listtemp.top-->",$listtemp_r[0],$searchtemp);
	$searchtemp=str_replace("<!--empire.listtemp.footer-->",$listtemp_r[2],$searchtemp);
	//列表中间
	$listtemp_center=str_replace("[!--title--]","<?=\$r[title]?>",$listtemp_r[1]);
	$listtemp_center=str_replace("[!--titleurl--]","<?=\$titleurl?>",$listtemp_center);
	$listtemp_center=str_replace("[!--smalltext--]","<?=\$smalltext?>",$listtemp_center);
	$listtemp_center=str_replace("[!--id--]","<?=\$r[id]?>",$listtemp_center);
	$listtemp_center=str_replace("[!--onclick--]","<?=\$r[onclick]?>",$listtemp_center);
	$listtemp_center=str_replace("[!--username--]","<?=\$r[username]?>",$listtemp_center);
	$listtemp_center=str_replace("[!--writer--]","<?=\$r[writer]?>",$listtemp_center);
	$listtemp_center=str_replace("[!--befrom--]","<?=\$r[befrom]?>",$listtemp_center);
	$listtemp_center=str_replace("[!--newstime--]","<?=\$r[newstime]?>",$listtemp_center);
	$listtemp_center=str_replace("[!--no--]","<?=\$no?>",$listtemp_center);
	$listtemp_center=str_replace("[!--titlelink--]","<?=\$titlelink?>",$listtemp_center);
	$listtemp_center=str_replace("[!--classname--]","<?=\$classname?>",$listtemp_center);
	$searchtemp=str_replace("<!--empire.listtemp.center-->",$listtemp_center,$searchtemp);
	//WriteFiletext($filename,$searchtemp);
	*/
	//------生成评论文件
	$pl_t_filename="../data/template/pltemp.php";
	$pl_filename="../pl/index.php";
	$pltemp=ReadFiletext($pl_t_filename);
	$pltemp=str_replace("\\","\\\\",$pltemp);
	//导航栏
	$url="<a href=".$public_r[newsurl].">".$fun_r['index']."</a>&nbsp;>&nbsp;[!--title--]&nbsp;>&nbsp;".$fun_r['newspl']."&nbsp;>";
	//取得评论页面模板
	$pl_r=$empire->fetch1("select pllisttemp from ".GetTemptb("enewspubtemp")." limit 1");
	$pl_r['pllisttemp']=ReplaceTempvar($pl_r['pllisttemp']);//公共模板变量
	$pl_r['pllisttemp']=str_replace("[!--pagetitle--]",$fun_r['newspl'],$pl_r['pllisttemp']);

	$pl_r[pllisttemp]=str_replace("[!--url--]","<?=\$url?>",$pl_r[pllisttemp]);
	$pl_r[pllisttemp]=RepSearchRtemp($pl_r[pllisttemp],$url);
	$pl_r[pllisttemp]=str_replace("[!--title--]","<?=\$title?>",$pl_r[pllisttemp]);
	$pl_r[pllisttemp]=str_replace("[!--titleurl--]","<?=\$titleurl?>",$pl_r[pllisttemp]);
	$pl_r[pllisttemp]=str_replace("[!--id--]","<?=\$id?>",$pl_r[pllisttemp]);
	$pl_r[pllisttemp]=str_replace("[!--classid--]","<?=\$classid?>",$pl_r[pllisttemp]);
	$pl_r[pllisttemp]=str_replace("[!--plnum--]","<?=\$num?>",$pl_r[pllisttemp]);
	//评分
	$pl_r[pllisttemp]=str_replace("[!--pinfopfen--]","<?=\$pinfopfen?>",$pl_r[pllisttemp]);
	$pl_r[pllisttemp]=str_replace("[!--infopfennum--]","<?=\$infopfennum?>",$pl_r[pllisttemp]);
	$pl_r[pllisttemp]=str_replace("[!--key.url--]",$public_r[newsurl]."e/ShowKey?ecms",$pl_r[pllisttemp]);
	$pl_r[pllisttemp]=str_replace("[!--lusername--]","<?=\$lusername?>",$pl_r[pllisttemp]);
	$pl_r[pllisttemp]=str_replace("[!--lpassword--]","<?=\$lpassword?>",$pl_r[pllisttemp]);
	$pl_r[pllisttemp]=str_replace("[!--news.url--]",$public_r[newsurl],$pl_r[pllisttemp]);
	$listtemp_r=explode("[!--empirenews.listtemp--]",$pl_r[pllisttemp]);
	$pltemp=str_replace("<!--empire.listtemp.top-->",$listtemp_r[0],$pltemp);
	$pltemp=str_replace("<!--empire.listtemp.footer-->",$listtemp_r[2],$pltemp);
	//列表中间
	$listtemp_center=str_replace("[!--plid--]","<?=\$r[plid]?>",$listtemp_r[1]);
	$listtemp_center=str_replace("[!--pltext--]","<?=\$r[saytext]?>",$listtemp_center);
	$listtemp_center=str_replace("[!--pltime--]","<?=\$r[saytime]?>",$listtemp_center);
	$listtemp_center=str_replace("[!--plip--]","<?=\$r[sayip]?>",$listtemp_center);
	$listtemp_center=str_replace("[!--id--]","<?=\$id?>",$listtemp_center);
	$listtemp_center=str_replace("[!--classid--]","<?=\$classid?>",$listtemp_center);
	$listtemp_center=str_replace("[!--username--]","<?=\$r[username]?>",$listtemp_center);
	$listtemp_center=str_replace("[!--includelink--]","<?=\$includelink?>",$listtemp_center);
	$listtemp_center=str_replace("[!--zcnum--]","<?=\$r[zcnum]?>",$listtemp_center);
	$listtemp_center=str_replace("[!--fdnum--]","<?=\$r[fdnum]?>",$listtemp_center);
	$pltemp=str_replace("<!--empire.listtemp.center-->",$listtemp_center,$pltemp);
    WriteFiletext($pl_filename,$pltemp);
}

//生成留言板文件
function ReGbooktemp(){
	global $empire,$public_r,$fun_r,$dbtbpre;
	$tfile="../data/template/gbooktemp.php";
	$file="../tool/gbook/index.php";
	$gbtemp=ReadFiletext($tfile);
	//取得留言页面模板
	$pr=$empire->fetch1("select gbooktemp from ".GetTemptb("enewspubtemp")." limit 1");
	$pr['gbooktemp']=ReplaceTempvar($pr['gbooktemp']);//公共模板变量
	$pr['gbooktemp']=str_replace("[!--news.url--]",$public_r['newsurl'],$pr['gbooktemp']);
	$pr['gbooktemp']=str_replace("[!--pagetitle--]",$fun_r['saygbook'],$pr['gbooktemp']);
	$pr['gbooktemp']=str_replace("[!--url--]","<?=\$url?>",$pr['gbooktemp']);
	$pr['gbooktemp']=RepSearchRtemp($pr['gbooktemp'],$url);
	$pr['gbooktemp']=str_replace("[!--bname--]","<?=\$bname?>",$pr['gbooktemp']);
	$pr['gbooktemp']=str_replace("[!--bid--]","<?=\$bid?>",$pr['gbooktemp']);

	$listtemp_r=explode("[!--empirenews.listtemp--]",$pr['gbooktemp']);
	$gbtemp=str_replace("<!--empire.listtemp.top-->",$listtemp_r[0],$gbtemp);
	$gbtemp=str_replace("<!--empire.listtemp.footer-->",$listtemp_r[2],$gbtemp);
	//---列表中间
	//处理回复
	$restart="
<?
if(\$r[retext])
{
?>
";
	$endstart="
<?
}
?>";
	$listtemp_center=str_replace("[!--start.regbook--]",$restart,$listtemp_r[1]);
	$listtemp_center=str_replace("[!--end.regbook--]",$endstart,$listtemp_center);

	$listtemp_center=str_replace("[!--lyid--]","<?=\$r[lyid]?>",$listtemp_center);
	$listtemp_center=str_replace("[!--name--]","<?=\$r[name]?>",$listtemp_center);
	$listtemp_center=str_replace("[!--email--]","<?=\$r[email]?>",$listtemp_center);
	$listtemp_center=str_replace("[!--call--]","<?=\$r[call]?>",$listtemp_center);
	$listtemp_center=str_replace("[!--lytime--]","<?=\$r[lytime]?>",$listtemp_center);
	$listtemp_center=str_replace("[!--lytext--]","<?=\$r[lytext]?>",$listtemp_center);
	$listtemp_center=str_replace("[!--retext--]","<?=\$r[retext]?>",$listtemp_center);

	$gbtemp=str_replace("<!--empire.listtemp.center-->",$listtemp_center,$gbtemp);
	WriteFiletext($file,$gbtemp);
}

//更新控制面板模板
function ReCptemp(){
	global $empire,$public_r,$dbtbpre,$fun_r;
	$pr=$empire->fetch1("select cptemp from ".GetTemptb("enewspubtemp")." limit 1");
	$pr['cptemp']=ReplaceTempvar($pr['cptemp']);
	$pr['cptemp']=str_replace("[!--pagetitle--]",$fun_r['membercp'],$pr['cptemp']);
	//生成头尾文件
	$temptext=str_replace("[!--newsnav--]","<?=\$url?>",$pr['cptemp']);//导航条
	$temptext=str_replace("[!--news.url--]",$public_r['newsurl'],$temptext);
	$r=explode("[!--empirenews.template--]",$temptext);
	$file1="../data/template/cp_1.php";
	WriteFiletext($file1,$r[0]);
	$file2="../data/template/cp_2.php";
	WriteFiletext($file2,$r[1]);
}

//更新登陆状态模板
function ReLoginIframe(){
	global $empire,$public_r,$dbtbpre;
	$tfile="../data/template/loginiframetemp.php";
	$loginiframetemp=ReadFiletext($tfile);
	$pr=$empire->fetch1("select loginiframe,loginjstemp from ".GetTemptb("enewspubtemp")." limit 1");
	//框架登陆状态调用
	$temptext=str_replace("[!--news.url--]",$public_r['newsurl'],$pr['loginiframe']);
	$temptext=str_replace("[!--userid--]","<?=\$myuserid?>",$temptext);
	$temptext=str_replace("[!--username--]","<?=\$myusername?>",$temptext);
	$temptext=str_replace("[!--groupname--]","<?=\$groupname?>",$temptext);
	$temptext=str_replace("[!--money--]","<?=\$money?>",$temptext);
	$temptext=str_replace("[!--userdate--]","<?=\$userdate?>",$temptext);
	$temptext=str_replace("[!--havemsg--]","<?=\$havemsg?>",$temptext);
	$temptext=str_replace("[!--userfen--]","<?=\$userfen?>",$temptext);
	$r=explode("[!--empirenews.template--]",$temptext);
	$text=str_replace("<!--login-->",$r[0],$loginiframetemp);
	$text=str_replace("<!--loginin-->",$r[1],$text);
	$file="../member/iframe/index.php";
	WriteFiletext($file,$text);
	//JS登陆状态调用
	$temptext=str_replace("[!--news.url--]",$public_r['newsurl'],$pr['loginjstemp']);
	$temptext=str_replace("[!--userid--]","<?=\$myuserid?>",$temptext);
	$temptext=str_replace("[!--username--]","<?=\$myusername?>",$temptext);
	$temptext=str_replace("[!--groupname--]","<?=\$groupname?>",$temptext);
	$temptext=str_replace("[!--money--]","<?=\$money?>",$temptext);
	$temptext=str_replace("[!--userdate--]","<?=\$userdate?>",$temptext);
	$temptext=str_replace("[!--havemsg--]","<?=\$havemsg?>",$temptext);
	$temptext=str_replace("[!--userfen--]","<?=\$userfen?>",$temptext);
	$r=explode("[!--empirenews.template--]",$temptext);
	$login="document.write(\"".addslashes(stripSlashes(str_replace("\r\n","",$r[0])))."\");";
	$loginin="document.write(\"".addslashes(stripSlashes(str_replace("\r\n","",$r[1])))."\");";
	$text=str_replace("<!--login-->",$login,$loginiframetemp);
	$text=str_replace("<!--loginin-->",$loginin,$text);
	$file="../member/login/loginjs.php";
	WriteFiletext_n($file,$text);
}

//退出登陆
function loginout($userid,$username,$rnd){
	global $empire,$dbtbpre;
	$userid=(int)$userid;
	if(!$userid||!$username)
	{
		printerror("NotLogin","history.go(-1)");
	}
	$set1=esetcookie("loginuserid","",0);
	$set2=esetcookie("loginusername","",0);
	$set3=esetcookie("loginrnd","",0);
	$set4=esetcookie("loginlevel","",0);
	//取得随机密码
	$rnd=make_password(20);
	$sql=$empire->query("update {$dbtbpre}enewsuser set rnd='$rnd' where userid='$userid'");
	//操作日志
	insert_dolog("");
	printerror("ExitSuccess","index.php");
}

//替换关键字
function ReplaceKey($newstext){
	global $empire,$dbtbpre;
	if(empty($newstext))
	{return $newstext;}
	$sql=$empire->query("select keyname,keyurl from {$dbtbpre}enewskey");
	while($r=$empire->fetch($sql))
	{
		$newstext=str_replace($r[keyname],"<a href='".$r[keyurl]."' target='_blank' class='infotextkey'>".$r[keyname]."</a>",$newstext);
	}
	return $newstext;
}

//替换禁用字符
function ReplaceWord($newstext){
	global $empire,$dbtbpre;
	if(empty($newstext))
	{return $newstext;}
	$sql=$empire->query("select newword,oldword from {$dbtbpre}enewswords");
	while($r=$empire->fetch($sql))
	{
		$newstext=str_replace($r[oldword],$r[newword],$newstext);
	}
	return $newstext;
}

//投票组合
function ReturnVote($votename,$votenum,$delvid,$vid,$enews=0){
	global $empire,$dbtbpre;
	$f_exp="::::::";
	$r_exp="\r\n";
	$returnstr="";
	//增加投票
	if(empty($enews))
	{
		for($i=0;$i<count($votename);$i++)
		{
			//替换非法字符
			$name=str_replace($f_exp,"",$votename[$i]);
			$name=str_replace($r_exp,"",$votename[$i]);
			$num=str_replace($f_exp,"",$votenum[$i]);
			$num=str_replace($r_exp,"",$votenum[$i]);
			if($name)
			{
				if(empty($num))
				{$num=0;}
				$returnstr.=$name.$f_exp.$num.$r_exp;
			}
		}
	}
	//修改投票
	else
	{
		for($i=0;$i<count($votename);$i++)
		{
			//删除下载地址
			$del=0;
			for($j=0;$j<count($delvid);$j++)
			{
				if($delvid[$j]==$vid[$i])
				{$del=1;}
			}
			if($del)
			{continue;}
			//替换非法字符
			$name=str_replace($f_exp,"",$votename[$i]);
			$name=str_replace($r_exp,"",$votename[$i]);
			$num=str_replace($f_exp,"",$votenum[$i]);
			$num=str_replace($r_exp,"",$votenum[$i]);
			if($name)
			{
				if(empty($num))
				{$num=0;}
				$returnstr.=$name.$f_exp.$num.$r_exp;
			}
		}
	}
	/*
	if(empty($returnstr))
	{printerror("EmptyVotenum","history.go(-1)");}
	*/
	//去掉最后的字符
	$returnstr=substr($returnstr,0,strlen($returnstr)-2);
	return $returnstr;
}

//返回投票模板
function ReturnVoteTemp($tempid,$enews=0){
	global $empire;
	$r=$empire->fetch1("select temptext from ".GetTemptb("enewsvotetemp")." where tempid='$tempid'");
	if($enews)
	{
		$r[temptext]=str_replace("\r\n","",$r[temptext]);
	}
	return $r[temptext];
}

//替换投票模板总体变量
function RepVoteTempAllvar($temptext,$r){
	global $public_r;
	$action=$public_r['newsurl']."e/enews/index.php";
	$temptext=str_replace("[!--vote.action--]",$action,$temptext);
	$temptext=str_replace("[!--title--]",$r[title],$temptext);
	$viewurl=$public_r[newsurl]."e/tool/vote?voteid=".$r[voteid];
	$temptext=str_replace("[!--vote.view--]",$viewurl,$temptext);
	$temptext=str_replace("[!--width--]",$r[width],$temptext);
	$temptext=str_replace("[!--height--]",$r[height],$temptext);
	$temptext=str_replace("[!--voteid--]",$r[voteid],$temptext);
	$temptext=str_replace("[!--id--]",$r[id],$temptext);
	$temptext=str_replace("[!--classid--]",$r[classid],$temptext);
	return $temptext;
}

//替换投票模板列表
function RepVoteTempListvar($temptext,$votebox,$votename){
	$temptext=str_replace("[!--vote.box--]",$votebox,$temptext);
	$temptext=str_replace("[!--vote.name--]",$votename,$temptext);
	return $temptext;
}

//栏目缓存
function GetClass(){
	global $empire,$dbtbpre,$editor;
	if($editor==1)
	{
		$apath="../";
	}
	$line=250;
	$sql=$empire->query("select * from {$dbtbpre}enewsclass order by classid desc");
	$num=$empire->num1($sql);
	$filename=$apath."../class/class.php";
	$no=0;
	$p=0;
	$l="";
	$mod="";
	$modstr=",";
	while($r=$empire->fetch($sql))
	{
		$no++;
		$l="";
		//外部栏目
		if($r[wburl])
		{
			$l=",
'wburl'=>'".addslashes($r[wburl])."'";
		}
		//终极栏目
		elseif($r[islast])
		{
			//组合模型
			if(empty($mod[$r[modid]]))
			{
				$mod[$r[modid]]="|";
		    }
			$mod[$r[modid]].=$r[classid]."|";
			if(!strstr($modstr,",".$r[modid].","))
			{
				$modstr.=$r[modid].",";
			}
			$l=",
'lencord'=>".$r[lencord].",
'link_num'=>".$r[link_num].",
'newstempid'=>".$r[newstempid].",
'listtempid'=>".$r[listtempid].",
'newspath'=>'".addslashes($r[newspath])."',
'filename'=>".$r[filename].",
'ipath'=>'".addslashes($r[ipath])."',
'filetype'=>'".addslashes($r[filetype])."',
'openpl'=>".$r[openpl].",
'openadd'=>".$r[openadd].",
'groupid'=>'".addslashes($r[groupid])."',
'filename_qz'=>'".addslashes($r[filename_qz])."',
'checked'=>".$r[checked].",
'docheckuser'=>".$r[docheckuser].",
'checkuser'=>'".addslashes($r[checkuser])."',
'bname'=>'".addslashes($r[bname])."',
'reorderf'=>'".addslashes($r[reorderf])."',
'reorder'=>'".addslashes($r[reorder])."',
'checkpl'=>".$r[checkpl].",
'listdt'=>".$r[listdt].",
'showdt'=>".$r[showdt];
	    }
		else
		{
			//列表式
			if($r[islist]&&empty($r[islast]))
			{
				$l=",
'lencord'=>".$r[lencord].",
'reorderf'=>'".addslashes($r[reorderf])."',
'reorder'=>'".addslashes($r[reorder])."',
'listtempid'=>".$r[listtempid].",
'islist'=>".$r[islist].",
'listdt'=>".$r[listdt];
			}
			elseif($r[listtempid])
			{
				$l=",
'lencord'=>".$r[lencord].",
'reorderf'=>'".addslashes($r[reorderf])."',
'reorder'=>'".addslashes($r[reorder])."',
'listtempid'=>".$r[listtempid];
			}
		}
		if($r[dtlisttempid])
		{
			$l.=",
'dtlisttempid'=>".$r[dtlisttempid];
		}
		$classes.="\$class_r[".$r[classid]."]=Array('classid'=>".$r[classid].",
'bclassid'=>".$r[bclassid].",
'classname'=>'".addslashes($r[classname])."',
'sonclass'=>'".addslashes($r[sonclass])."',
'featherclass'=>'".addslashes($r[featherclass])."',
'islast'=>".$r[islast].",
'classpath'=>'".addslashes($r[classpath])."',
'classtype'=>'".addslashes($r[classtype])."',
'classurl'=>'".addslashes($r[classurl])."',
'searchtempid'=>".$r[searchtempid].",
'maxnum'=>".$r[maxnum].",
'down_num'=>".$r[down_num].",
'online_num'=>".$r[online_num].",
'tbname'=>'".addslashes($r[tbname])."',
'modid'=>".$r[modid].$l.");
";
		if($no%$line==0||($num%$line<>0&&$num==$no))
		{
			$p++;
			$file="class".$p.".php";
			$include.="@include(\"".$file."\");\r\n";
			$classes="<?
".$classes."?>";
			WriteFiletext_n($apath."../class/".$file,$classes);
			$classes="";
        }
	}
	//-----专题缓存
	$zsql=$empire->query("select * from {$dbtbpre}enewszt order by ztid desc");
	$zt="";
	$zfile=$apath."../class/ztclass.php";
	while($zr=$empire->fetch($zsql))
	{
		$zt.="\$class_zr[".$zr[ztid]."]=Array('ztid'=>".$zr[ztid].",
'ztname'=>'".addslashes($zr[ztname])."',
'ztnum'=>".$zr[ztnum].",
'listtempid'=>".$zr[listtempid].",
'ztpath'=>'".addslashes($zr[ztpath])."',
'zttype'=>'".addslashes($zr[zttype])."',
'zturl'=>'".addslashes($zr[zturl])."',
'islist'=>".$zr[islist].",
'maxnum'=>".$zr[maxnum].",
'reorderf'=>'".addslashes($zr[reorderf])."',
'reorder'=>'".addslashes($zr[reorder])."',
'tbname'=>'".addslashes($zr[tbname])."');
";
	}
	$zt="<?
".$zt."?>";
	WriteFiletext_n($zfile,$zt);
	$include.="@include(\"ztclass.php\");\r\n";
	$include="<?
\$class_r=array();
\$class_zr=array();
".$include."
?>";
	WriteFiletext_n($filename,$include);
	//组合模型
	$er=explode(",",$modstr);
	for($i=1;$i<count($er)-1;$i++)
	{
		$mid=$er[$i];
		$usql=$empire->query("update {$dbtbpre}enewsmod set sonclass='".$mod[$mid]."' where mid='$mid'");
    }
}

//显示无限级栏目[增加栏目时]
function ShowClass_AddClass($adminclass,$obclassid,$bclassid,$exp,$modid,$enews=0,$addminfocid=''){
	global $empire,$dbtbpre;
	if(empty($bclassid))
	{
		$bclassid=0;
		$exp="|-";
		if($enews==2)
		{
			$modr=$empire->fetch1("select sonclass from {$dbtbpre}enewsmod where mid='$modid'");
			$addminfocid=$modr['sonclass'];
		}
    }
	else
	{$exp="&nbsp;&nbsp;".$exp;}
	$sql=$empire->query("select classid,classname,bclassid,islast,openadd,modid,sonclass from {$dbtbpre}enewsclass where bclassid='$bclassid' and wburl='' order by myorder,classid");
	$returnstr="";
	while($r=$empire->fetch($sql))
	{
		//投稿显示
		if($enews==2)
		{
			if($r[openadd])
			{
				continue;
			}
			if(CheckHaveInClassid($r,$addminfocid)==0)
			{
				continue;
			}
		}
		if($r[islast])
		{
			if(empty($enews)||$enews==2||$enews==3||$enews==4)
			{
				$color=" style='background:#99C4E3'";
			}
			//隐藏不能投稿的栏目
			if($enews==2)
			{
				if($modid)
				{
					if($r[modid]<>$modid)
				    {continue;}
				}
			}
			//模型
			if($enews==4)
			{
				if($r[modid]<>$modid)
				{continue;}
			}
		}
		else
		{$color="";}
		if($r[classid]==$obclassid)
		{$select=" selected";}
		else
		{$select="";}
		//-----------增加用户时
		if($enews==3)
		{
			$c=explode("|".$r[classid]."|",$adminclass);
			if(count($c)>1)
			{$select=" selected";}
			else
			{$select="";}
	    }
		$returnstr.="<option value=".$r[classid].$select.$color.">".$exp.$r[classname]."</option>";
		$returnstr.=ShowClass_AddClass($adminclass,$obclassid,$r[classid],$exp,$modid,$enews,$addminfocid);
	}
	return $returnstr;
}

//设置伸缩
function SetDisplayClass($open){
	$time=time()+365*24*3600;
	$set=esetcookie("displayclass",$open,$time);
	echo"<script>self.location.href='ListClass.php';</script>";
	exit();
}

//删除目录函数
function DelPath($DelPath){
	if($DelPath=="../../"||$DelPath=="../../d/file/")
	{return "";}
	$wm_chief=new del_path();
	$wm_chief_ok=$wm_chief->wm_chief_delpath($DelPath);
	return $wm_chief_ok;
}

//复制目录
function CopyPath($oldpath,$newpath){
	$wm_chief=new copy_path();
    $wm_chief_ok=$wm_chief->wm_chief_copypath($oldpath,$newpath);
	return $wm_chief_ok;
}

//移动目录
function MovePath($oldpath,$newpath){
	//复制
	CopyPath($oldpath,$newpath);
	//删除
	DelPath($oldpath);
}

//级别缓存
function GetMemberLevel(){
	global $empire,$dbtbpre;
	$file="../class/MemberLevel.php";
	$sql=$empire->query("select * from {$dbtbpre}enewsmembergroup order by groupid");
	while($r=$empire->fetch($sql))
	{
		$levels.="\$level_r[".$r[groupid]."]=Array('groupid'=>".$r[groupid].",
'groupname'=>'".addslashes($r[groupname])."',
'level'=>".$r[level].",
'checked'=>".$r[checked].",
'favanum'=>".$r[favanum].",
'daydown'=>".$r[daydown].",
'msglen'=>".$r[msglen].",
'regchecked'=>".$r[regchecked].",
'spacestyleid'=>".$r[spacestyleid].",
'msgnum'=>".$r[msgnum].");
";
	}
	$levels="<?
//level
\$level_r=array();
".$levels."
//level
?>";
	WriteFiletext_n($file,$levels);
}

//##############################采集功能开始###############################

//替换回车
function ReplaceFc($text){
	$text=str_replace("\n","",$text);
	$text=str_replace("\r","",$text);
	return $text;
}

//返回字符正则
function GetInfoStr($text,$exp,$enews=0){
	$e1="[phome-".$exp."]";
	$e2="[/phome-".$exp."]";
	$rep="[!--".$exp."--]";
	$mode="*";
	//匹配多个
	if($enews==1)
	{
		$cr=explode($rep,$text);
		$cer=explode($mode,$cr[0]);
		$num=count($cer)-1;
	}
	//转换字符
	$text=str_replace($rep,$mode,$text);
	$er=explode($mode,$text);
	$newtext="";
	for($i=0;$i<count($er);$i++)
	{
		$j=$i+1;
		//加标签
		if($enews==1)
		{
			if($i==$num)
			{
				$newtext.=$er[$i].$e1."\\".$j.$e2;
			}
			else
			{
				$newtext.=$er[$i]."\\".$j;
			}
		}
		//过滤广告
		elseif($enews==2)
		{
			if($i==$num)
			{
				$newtext.=$er[$i]."";
			}
			else
			{
				$newtext.=$er[$i]."\\".$j;
			}
		}
		else
		{
			$newtext.=$er[$i]."\\".$j;
		}
	}
	//去掉最后一个//
	$newtext=substr($newtext,0,strlen($newtext)-2);
	return $newtext;
}

//过滤广告
function RepAd($repad,$text){
	if(empty($repad))
	{return $text;}
	$repad=stripSlashes($repad);
	//替换回车
	$repad=ReplaceFc($repad);
	$r=explode(",",$repad);
	$exp="ad";
	for($i=0;$i<count($r);$i++)
	{
		$zztext=RepInfoZZ($r[$i],$exp,0);
		//$strtext=GetInfoStr($r[$i],$exp,2);
		$strtext="";
		$text=stripSlashes(preg_replace($zztext,$strtext,$text));
	}
	return $text;
}

//过滤整个页面广告
function RepPageAd($repad,$text){
	if(empty($repad))
	{return $text;}
	$repad=stripSlashes($repad);
	//替换回车
	$repad=ReplaceFc($repad);
	$r=explode(",",$repad);
	$exp="pad";
	for($i=0;$i<count($r);$i++)
	{
		$zztext=RepInfoZZ($r[$i],$exp,0);
		//$strtext=GetInfoStr($r[$i],$exp,2);
		$strtext="";
		$text=stripSlashes(preg_replace($zztext,$strtext,$text));
	}
	return $text;
}

//替换字符
function RepInfoZZ($text,$exp,$enews=0){
	$text=str_replace("*","(.*?)",$text);
	$text=str_replace("[!--".$exp."--]","(.*?)",$text);
	//$text=str_replace("\\","\\\\",$text);
	//$text=str_replace("^","\^",$text);
	//$text=str_replace("\"","\"",$text);
	$text=str_replace("/","\/",$text);
	$text="/".$text."/is";
	return $text;
}

//取得符号位置
function CountCJ_site($text,$exp){
	$rep="[!--".$exp."--]";
	$mode="*";
	$cr=explode($rep,$text);
	$cer=explode($mode,$cr[0]);
	$num=count($cer);
	return $num;
}

//取得替换空余出来的值
function ReturnCJ_str($text,$exp,$info){
	$e1="[phome-".$exp."]";
	$e2="[/phome-".$exp."]";
	$text=stripSlashes(stripSlashes($text));
	//替换回车
	$text=ReplaceFc($text);
	$rep="[!--".$exp."--]";
	//替换
	$num=CountCJ_site($text,$exp);//取得符号位置
	$zztext=RepInfoZZ($text,$exp,0);
	$text1=stripSlashes(preg_replace($zztext,$e1."\\".$num.$e2,$info));
	$r=explode($e1,$text1);
	$r1=explode($e2,$r[1]);
	$text1=$r1[0];
	return $text1;
}

//替换链接
function RepCjUrlStr($url){
	$url=strip_tags($url);
	$url=str_replace("\"","",$url);
	$url=str_replace("'","",$url);
	$url=str_replace("&amp;","&",$url);
	return $url;
}

//编码转换
function doCjUtfAndGbk($str,$phome=0){
	//正常编码
	if($phome==0)
	{
		return $str;
	}
	if($phome==1)//UTF8->GB2312
	{
		$str=DoIconvVal("UTF8","GB2312",$str);
	}
	elseif($phome==2)//UTF8->BIG5
	{
		$str=DoIconvVal("UTF8","BIG5",$str);
	}
	elseif($phome==3)//BIG5->GB2312
	{
		$str=DoIconvVal("BIG5","GB2312",$str);
	}
	elseif($phome==4)//GB2312->BIG5
	{
		$str=DoIconvVal("GB2312","BIG5",$str);
	}
	elseif($phome==5)//UNICODE->GB2312
	{
		$str=DoIconvVal("UNICODE","GB2312",$str);
	}
	elseif($phome==6)//UNICODE->BIG5
	{
		$str=DoIconvVal("UNICODE","BIG5",$str);
	}
	elseif($phome==7)//GB2312->UTF8
	{
		$str=DoIconvVal("GB2312","UTF8",$str);
	}
	elseif($phome==8)//BIG5->UTF8
	{
		$str=DoIconvVal("BIG5","UTF8",$str);
	}
	elseif($phome==9)//UNICODE->UTF8
	{
		$str=DoIconvVal("UNICODE","UTF8",$str);
	}
	else
	{}
	return $str;
}

//替换采集页面内容
function RepCjPagetextStr($text,$r){
	$text=str_replace("\\","/",$text);
	//编码转换
	$text=doCjUtfAndGbk($text,$r['enpagecode']);
	//替换
	$text=RepInfoWord($text,$r['oldpagerep'],$r['newpagerep']);
	//替换页面过滤正则
	$text=RepPageAd($r['pagerepad'],$text);
	return $text;
}

//取得地址
function EchoUrl($text,$exp,$exp1,$dr,$url,$classid,$num,$checkrnd){
	global $empire,$fun_r,$dbtbpre;
	$e1="[phome-".$exp."]";
	$e2="[/phome-".$exp."]";
	$ep1="[phome-".$exp1."]";
	$ep2="[/phome-".$exp1."]";
	$r=explode($e1,$text);
	//图片链接
	if(!$dr[z_titlepicl]&&$dr[zz_titlepicl])
	{
		$rp=explode($ep1,$text);
	}
	else
	{
		$titlepic=$dr[z_titlepicl];
	}
	for($i=1;$i<count($r)&&$i<=$num;$i++)
	{
		$r1=explode($e2,$r[$i]);
		$dourl=trim($r1[0]);
		//是否有http
		if(strstr($dourl,"http://")||strstr($dourl,"https://"))
		{}
		else
		{
			$dourl=$url.$dourl;
		}
		//替换地址
		$dourl=RepCjUrlStr($dourl);
		if(empty($dourl))
		{continue;}
		$dourl=addslashes($dourl);
		//---------------检查数据库是否有记录
		if(empty($dr[recjtheurl]))//重复采集
		{
			$dbnum=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_infotmp_".$dr[tbname]." where oldurl='$dourl' limit 1");
			if($dbnum)
			{continue;}
		}
		//图片链接
		if(!$dr[z_titlepicl]&&$dr[zz_titlepicl])
	    {
			$rp1=explode($ep2,$rp[$i]);
			$titlepic=trim($rp1[0]);
			//是否有http
			if(strstr($titlepic,"http://")||strstr($titlepic,"https://"))
			{}
			else
			{$titlepic=$dr[qz_titlepicl].$titlepic;}
			//替换地址
			$titlepic=RepCjUrlStr($titlepic);
			$titlepic=addslashes($titlepic);
	    }
		//将地址写入数据库
		$sql=$empire->query("insert into {$dbtbpre}enewslinktmp(newsurl,checkrnd,titlepic) values('$dourl','$checkrnd','$titlepic');");
		echo $dourl."<br>";
	}
}

//采集直接内容页地址
function PageEchoUrl($classid,$cr,$userid,$username){
	global $empire,$fun_r,$dbtbpre;
	//取得条数
	if(empty($cr[num]))
	{$cr[num]=10000;}
	//生成检测值
	$checkrnd=md5(uniqid(microtime()));

	$url_r=explode("\r\n",$cr[infourl]);
	$count=count($url_r);
	if($count>$cr[num])
	{
		$count=$cr[num];
	}
	for($i=0;$i<$count;$i++)
	{
		$dourl=trim($url_r[$i]);
		if(empty($dourl))
		{
			continue;
		}
		//是否有http
		if(strstr($dourl,"http://")||strstr($dourl,"https://"))
		{}
		else
		{
			$dourl=$cr[httpurl].$dourl;
		}
		//替换地址
		$dourl=RepCjUrlStr($dourl);
		if(empty($dourl))
		{continue;}
		$dourl=addslashes($dourl);
		//---------------检查数据库是否有记录
		if(empty($cr[recjtheurl]))//重复采集
		{
			$dbnum=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_infotmp_".$cr[tbname]." where oldurl='$dourl' limit 1");
			if($dbnum)
			{continue;}
		}
		//将地址写入数据库
		$sql=$empire->query("insert into {$dbtbpre}enewslinktmp(newsurl,checkrnd,titlepic) values('$dourl','$checkrnd','');");
		echo $dourl."<br>";
	}
	echo $fun_r['GetUrlOver']."<script>self.location.href='enews.php?enews=GetNewsInfo&classid=$classid&start=0&checkrnd=$checkrnd';</script>";
	exit();
}

//开始采集远程地址
function CJUrl($classid,$start,$checkrnd,$userid,$username){
	global $empire,$fun_r,$dbtbpre;
	$classid=(int)$classid;
	if(empty($classid))
	{printerror("NotChangeCjid","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"cj");
	$r=$empire->fetch1("select endday,num,zz_smallurl,zz_newsurl,httpurl,infourl,newsclassid,relistnum,zz_titlepicl,z_titlepicl,qz_titlepicl,save_titlepicl,tbname,recjtheurl,enpagecode,pagerepad,oldpagerep,newpagerep,keeptime,infourlispage from {$dbtbpre}enewsinfoclass where classid='$classid'");
	if(empty($r[newsclassid]))
	{printerror("NotCjid","history.go(-1)");}
	//直接内容页链接列表
	if($r['infourlispage'])
	{
		PageEchoUrl($classid,$r,$userid,$username);
	}
	//导入编码文件
	if($r['enpagecode'])
	{
		@include_once("doiconv.php");
	}
	//取得条数
	if(empty($r[num]))
	{$r[num]=10000;}
	if(empty($r[relistnum]))
	{$r[relistnum]=1;}
	if(empty($start))
	{
		$start=0;
		//生成检测值
		$checkrnd=md5(uniqid(microtime()));
	}
	$exp="newsurl";
	$exp1="titlepic";
	//查看是否过期
	$b=0;
	$p=0;
	$url_r=explode("\r\n",$r[infourl]);
	$j=count($url_r);
	for($i=$start;$i<$j&&$p<$r[relistnum];$i++)
	{
		$p++;
		$b=1;
		$dourl=trim($url_r[$i]);
		if(empty($dourl))
		{continue;}
		//读取页面
		for($readnum=0;$readnum<3;$readnum++)
		{
			$text1=ReadFiletext($dourl);
			if(!empty($text1))
			{break;}
		}
		if(empty($text1))
		{continue;}
		//替换回车
		$text1=ReplaceFc($text1);
		//替换网页变量
		$text1=RepCjPagetextStr($text1,$r);
		//区域块
		if($r[zz_smallurl])
		{
			$text1=ReturnCJ_str($r[zz_smallurl],"smallurl",$text1);
			if(empty($text1))
			{
				continue;
			}
		}
		//替换内容链接
		$text=stripSlashes(stripSlashes($r[zz_newsurl]));
		//替换回车
		$text=ReplaceFc($text);
		$zztext=RepInfoZZ($text,$exp,0);
		$strtext=GetInfoStr($text,$exp,1);
		if($text)
		{
			$text1=stripSlashes(preg_replace($zztext,$strtext,$text1));
		}
		//替换标题图片地址
		if($r[zz_titlepicl]&&!$r[z_titlepicl])
		{
			$text=stripSlashes(stripSlashes($r[zz_titlepicl]));
			//替换回车
			$text=ReplaceFc($text);
			$zztext=RepInfoZZ($text,$exp1,0);
			$strtext=GetInfoStr($text,$exp1,1);
			if($text)
			{
				$text1=stripSlashes(preg_replace($zztext,$strtext,$text1));
			}
		}
		//链接写入数据库
		EchoUrl($text1,$exp,$exp1,$r,$r[httpurl],$classid,$r[num],$checkrnd);
	}
	$newstart=$i;
	//采集链接完毕
	if(empty($b))
	{
		echo $fun_r['GetUrlOver']."<script>self.location.href='enews.php?enews=GetNewsInfo&classid=$classid&start=0&checkrnd=$checkrnd';</script>";
		exit();
	}
	//echo $fun_r['GetOneListUrl']."<script>self.location.href='enews.php?enews=CjUrl&classid=$classid&start=$newstart&checkrnd=$checkrnd';</script>";
	echo"<meta http-equiv=\"refresh\" content=\"".$r['keeptime'].";url=enews.php?enews=CjUrl&classid=$classid&start=$newstart&checkrnd=$checkrnd\">".$fun_r['GetOneListUrl'];
	exit();
}

//###################采集页面列表##################
function ViewCjList($classid,$userid,$username){
	global $empire,$fun_r,$dbtbpre;
	$classid=(int)$classid;
	if(empty($classid))
	{printerror("NotChangeCjid","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"cj");
	$r=$empire->fetch1("select endday,num,zz_smallurl,zz_newsurl,httpurl,infourl,newsclassid,relistnum,zz_titlepicl,z_titlepicl,qz_titlepicl,save_titlepicl,infourlispage from {$dbtbpre}enewsinfoclass where classid='$classid'");
	if(empty($r[newsclassid]))
	{printerror("NotCjid","history.go(-1)");}
	//直接内容页列表
	if($r[infourlispage])
	{
		PageViewCjList($classid,$r,$userid,$username);
	}
	$url_r=explode("\r\n",$r[infourl]);
	$j=count($url_r);
	for($i=0;$i<$j;$i++)
	{
		if(empty($url_r[$i]))
		{continue;}
		$dourl=urlencode($url_r[$i]);
		$data.="<tr><td><a href='".$url_r[$i]."' target=_blank>".$url_r[$i]."</a></td><td align=center>[<a href='enews.php?enews=ViewCjUrl&classid=$classid&listpage=".$dourl."' target=_blank>".$fun_r['view']."</a>]</td></tr>";
    }
	$data="<p align=center><b>".$fun_r['CjListUrl']."</b></p><table width='96%' border=1 align=center cellpadding=3 cellspacing=0>
  <tr><td width=70% align=center><b>URL</b></td><td align=center><b>VIEW</b></td></tr>".$data."</table>";
	echo $data;
	exit();
}

//###################采集内容页面列表##################
function PageViewCjList($classid,$cr,$userid,$username){
	global $empire,$fun_r,$dbtbpre;
	//取得条数
	if(empty($cr[num]))
	{$cr[num]=10000;}
	$url_r=explode("\r\n",$cr[infourl]);
	$count=count($url_r);
	if($count>$cr[num])
	{
		$count=$cr[num];
	}
	for($i=0;$i<$count;$i++)
	{
		$dourl=trim($url_r[$i]);
		if(empty($dourl))
		{
			continue;
		}
		//是否有http
		if(strstr($dourl,"http://")||strstr($dourl,"https://"))
		{}
		else
		{
			$dourl=$cr[httpurl].$dourl;
		}
		//替换地址
		$dourl=RepCjUrlStr($dourl);
		if(empty($dourl))
		{continue;}
		$dourl=urlencode($dourl);
		$data.="<tr><td><a href='".$url_r[$i]."' target=_blank>".$url_r[$i]."</a></td><td align=center>[<a href='enews.php?enews=ViewGetNewsInfo&classid=$classid&newspage=".$dourl."' target=_blank>".$fun_r['view']."</a>]</td></tr>";
    }
	$data="<p align=center><b>".$fun_r['CjListUrl']."</b></p><table width='96%' border=1 align=center cellpadding=3 cellspacing=0>
  <tr><td width=70% align=center><b>URL</b></td><td align=center><b>VIEW</b></td></tr>".$data."</table>";
	echo $data;
	exit();
}

//#################预览采集列表
function ViewCjUrl($classid,$listpage,$userid,$username){
	global $empire,$fun_r,$dbtbpre;
	$classid=(int)$classid;
	if(empty($classid)||empty($listpage))
	{printerror("NotChangeCjid","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"cj");
	$r=$empire->fetch1("select endday,num,zz_smallurl,zz_newsurl,httpurl,infourl,newsclassid,relistnum,zz_titlepicl,z_titlepicl,qz_titlepicl,save_titlepicl,tbname,recjtheurl,enpagecode,pagerepad,oldpagerep,newpagerep from {$dbtbpre}enewsinfoclass where classid='$classid'");
	if(empty($r[newsclassid]))
	{printerror("NotCjid","history.go(-1)");}
	//导入编码文件
	if($r['enpagecode'])
	{
		@include_once("doiconv.php");
	}
	//取得条数
	if(empty($r[num]))
	{$r[num]=10000;}
	$exp="newsurl";
	$exp1="titlepic";
	$dourl=$listpage;
	//读取页面
	for($readnum=0;$readnum<3;$readnum++)
	{
		$text1=ReadFiletext($dourl);
		if(!empty($text1))
		{break;}
	}
	if(empty($text1))
	{
		printerror("FailCjUrl","history.go(-1)");
	}
	//替换回车
	$text1=ReplaceFc($text1);
	//替换网页变量
	$text1=RepCjPagetextStr($text1,$r);
	//区域块
	if($r[zz_smallurl])
	{
		$text1=ReturnCJ_str($r[zz_smallurl],"smallurl",$text1);
		if(empty($text1))
		{
			printerror("EmptyCjSmallUrl","history.go(-1)");
		}
	 }
	 //替换内容链接
	$text=stripSlashes(stripSlashes($r[zz_newsurl]));
	 //替换回车
	$text=ReplaceFc($text);
	$zztext=RepInfoZZ($text,$exp,0);
	$strtext=GetInfoStr($text,$exp,1);
	if($text)
	{
		$text1=stripSlashes(preg_replace($zztext,$strtext,$text1));
	}
	//替换标题图片地址
	if($r[zz_titlepicl]&&!$r[z_titlepicl])
	{
		$text=stripSlashes(stripSlashes($r[zz_titlepicl]));
		//替换回车
		$text=ReplaceFc($text);
		$zztext=RepInfoZZ($text,$exp1,0);
		$strtext=GetInfoStr($text,$exp1,1);
		if($text)
		{
			$text1=stripSlashes(preg_replace($zztext,$strtext,$text1));
		}
	}
	//输出地址
	echo"<p align=center><b>".$fun_r['CjListPageUrl']."</b></p><table width='96%' border=1 align=center cellpadding=3 cellspacing=0>
  <tr><td width=70% align=center><b>URL</b></td><td align=center><b>VIEW</b></td></tr>";
	ViewEchoUrl($text1,$exp,$exp1,$r,$r[httpurl],$classid,$r[num],$checkrnd);
	echo"</table>";
	exit();
}

//################输入采集页面
function ViewEchoUrl($text,$exp,$exp1,$dr,$url,$classid,$num,$checkrnd){
	global $empire,$fun_r,$dbtbpre;
	$e1="[phome-".$exp."]";
	$e2="[/phome-".$exp."]";
	$ep1="[phome-".$exp1."]";
	$ep2="[/phome-".$exp1."]";
	$r=explode($e1,$text);
	//图片链接
	if(!$dr[z_titlepicl]&&$dr[zz_titlepicl])
	{
		$rp=explode($ep1,$text);
	}
	else
	{
		$titlepic=$dr[z_titlepicl];
	}
	for($i=1;$i<count($r)&&$i<=$num;$i++)
	{
		$r1=explode($e2,$r[$i]);
		$dourl=trim($r1[0]);
		//是否有http
		if(strstr($dourl,"http://")||strstr($dourl,"https://"))
		{}
		else
		{
			$dourl=$url.$dourl;
		}
		//替换地址
		$dourl=RepCjUrlStr($dourl);
		if(empty($dourl))
		{continue;}
		$dourl=addslashes($dourl);
		//检查数据库是否有记录
		if(empty($dr[recjtheurl]))
		{
			$dbnum=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_infotmp_".$dr[tbname]." where oldurl='$dourl' limit 1");
			if($dbnum)
			{continue;}
		}
		//图片链接
		if(!$dr[z_titlepicl]&&$dr[zz_titlepicl])
	    {
			$rp1=explode($ep2,$rp[$i]);
			$titlepic=trim($rp1[0]);
			//是否有http
			if(strstr($titlepic,"http://")||strstr($titlepic,"https://"))
			{}
			else
			{$titlepic=$dr[qz_titlepicl].$titlepic;}
			//替换地址
			$titlepic=RepCjUrlStr($titlepic);
			$titlepic=addslashes($titlepic);
	    }
		if($titlepic)
		{$a="<br>(PIC:<a href='".$titlepic."' target=_blank>".$titlepic."</a>)";}
		echo "<tr><td><a href='".$dourl."' target=_blank>".$dourl."</a>".$a."</td><td align=center>[<a href='enews.php?enews=ViewGetNewsInfo&classid=$classid&newspage=".urlencode($dourl)."' target=_blank>".$fun_r['view']."</a>]</td></tr>";
	}
}

//#################################
//取得下载地址
function GetCjDownpath($text,$text1,$exp,$exp1,$url,$online=0){
	global $empire,$fun_r;
	if($online)
	{
		$fun_r[DownPath]="";
    }
	$e1="[phome-".$exp."]";
	$e2="[/phome-".$exp."]";
	$ep1="[phome-".$exp1."]";
	$ep2="[/phome-".$exp1."]";
	$r=explode($e1,$text);
	//名称
	if($text1)
	{
		$rp=explode($ep1,$text1);
	}
	$p=0;
	for($i=1;$i<count($r);$i++)
	{
		$r1=explode($e2,$r[$i]);
		$dourl=trim($r1[0]);
		if(empty($dourl))
		{continue;}
		if(!strstr($dourl,"://"))
		{
			$dourl=$url.$dourl;
		}
		if($text1)
		{
			$rp1=explode($ep2,$rp[$i]);
			$doname=trim($rp1[0]);
			if(empty($doname))
			{
				$doname=$fun_r[DownPath].($p+1);
			}
		}
		else
		{
			$doname=$fun_r[DownPath].($p+1);
		}
		$downname[$p]=$doname;
		$downpath[$p]=$dourl;
		$p++;
	}
	$down=ReturnDownpath($downname,$downpath,$delpathid,$pathid,$downuser,$fen,$thedownqz,$add,$foruser,$downurl,0);
	return $down;
}

//取得图片集地址
function GetCjMorepicpath($text,$text1,$text2,$exp,$exp1,$exp2,$url){
	global $empire;
	$e1="[phome-".$exp."]";
	$e2="[/phome-".$exp."]";
	$ep1="[phome-".$exp1."]";
	$ep2="[/phome-".$exp1."]";
	$epp1="[phome-".$exp2."]";
	$epp2="[/phome-".$exp2."]";
	$r=explode($e1,$text);
	//大图
	if($text1)
	{
		$rp=explode($ep1,$text1);
	}
	//名称
	if($text2)
	{
		$rpp=explode($epp1,$text2);
	}
	$p=0;
	for($i=1;$i<count($r);$i++)
	{
		$r1=explode($e2,$r[$i]);
		$dourl=trim($r1[0]);
		if(empty($dourl))
		{continue;}
		if(!strstr($dourl,"://"))
		{
			$dourl=$url.$dourl;
		}
		//大图
		if($text1)
		{
			$rp1=explode($ep2,$rp[$i]);
			$dobigurl=trim($rp1[0]);
			if(!empty($dobigurl))
			{
				if(!strstr($dobigurl,"://"))
				{
					$dobigurl=$url.$dobigurl;
				}
			}
		}
		else
		{
			$dobigurl="";
		}
		//图片名称
		if($text2)
		{
			$rpp1=explode($epp2,$rpp[$i]);
			$doname=trim($rpp1[0]);
		}
		else
		{
			$doname="";
		}
		$smallpic[$p]=$dourl;
		$bigpic[$p]=$dobigurl;
		$picname[$p]=$doname;
		$p++;
	}
	$down=ReturnMorepicpath($smallpic,$bigpic,$picname,$delpicid,$picid,$add,$downurl,0);
	return $down;
}

//取得地址前缀
function GetPageurlQz($self){
	$sr=explode("/",$self);
	$count=count($sr)-1;
	$sfile=$sr[$count];
	$r[selfqz]=substr($self,0,strlen($self)-strlen($sfile));
	//取得域名
	$sr1=explode("http://",$self);
	$sr2=explode("/",$sr1[1]);
	$r[domain]="http://".$sr2[0];
	return $r;
}

//内容页分页处理-下一页式
function GetMoreCjPagetext($self,$newstextzz,$smallpagezz,$pagezz,$pagetype,$firsttext,$the_r){
	if(empty($pagezz)||empty($newstextzz))
	{return "";}
	//是否保留分页
	$addpagetag=empty($the_r['doaddtextpage'])?'[!--empirenews.page--]':'';
	//取得地址前缀
	$sr=GetPageurlQz($self);
	$pagetext=$firsttext;
	$allpagetext="";
	for($i=0;$i<100;$i++)
	{
		//区域正则
		if($smallpagezz)
		{
			$pagetext=ReturnCJ_str($smallpagezz,"smallpagezz",$pagetext);
		}
		$nextlink=ReturnCJ_str($pagezz,"pagezz",$pagetext);
		if(empty($nextlink))
		{
			break;
		}
		if(!strstr($nextlink,"http://"))
		{
			//根目录开始
			if(strstr($nextlink,"/"))
			{
				$nextlink=$sr[domain].$nextlink;
			}
			else
			{
				$nextlink=$sr[selfqz].$nextlink;
			}
		}
		$nextlink=RepCjUrlStr($nextlink);
		if($nextlink==$self)
		{continue;}
		//取得远程数据
		for($j=0;$j<3;$j++)
		{
			$pagetext=ReadFiletext($nextlink);
			if($pagetext)
			{
				break;
			}
		}
		//页面不存在
		if(empty($pagetext))
		{
			break;
		}
		//替换网页变量
	    $pagetext=RepCjPagetextStr($pagetext,$the_r);
		//替换回车
		$pagetext=ReplaceFc($pagetext);
		$newstext=ReturnCJ_str($newstextzz,"newstext",$pagetext);
		if($newstext)
		{
			$allpagetext.=$addpagetag.$newstext;
		}
	}
	return $allpagetext;
}

//内容页分页处理-全部列表式
function GetMoreCjPagetextall($self,$newstextzz,$smallpagezz,$pagezz,$pagetype,$firsttext,$the_r){
	if(empty($pagezz)||empty($newstextzz))
	{return "";}
	//是否保留分页
	$addpagetag=empty($the_r['doaddtextpage'])?'[!--empirenews.page--]':'';
	$exp="pageallzz";
	//取得地址前缀
	$sr=GetPageurlQz($self);
	$pagetext=$firsttext;
	$allpagetext="";
	//区域正则
	if($smallpagezz)
	{
		$pagetext=ReturnCJ_str($smallpagezz,"smallpageallzz",$pagetext);
	}
	//分页
	$text=stripSlashes(stripSlashes($pagezz));
	//替换回车
	$text=ReplaceFc($text);
	$zztext=RepInfoZZ($text,$exp,0);
	$strtext=GetInfoStr($text,$exp,1);
	$pagetext=stripSlashes(preg_replace($zztext,$strtext,$pagetext));
	$e1="[phome-".$exp."]";
	$e2="[/phome-".$exp."]";
	$r=explode($e1,$pagetext);
	$count=count($r);
	for($i=1;$i<$count;$i++)
	{
		$r1=explode($e2,$r[$i]);
		$nextlink=trim($r1[0]);
		if(empty($nextlink))
		{continue;}
		if(!strstr($nextlink,"http://"))
		{
			//根目录开始
			if(strstr($nextlink,"/"))
			{
				$nextlink=$sr[domain].$nextlink;
			}
			else
			{
				$nextlink=$sr[selfqz].$nextlink;
			}
		}
		$nextlink=RepCjUrlStr($nextlink);
		if($nextlink==$self)
		{continue;}
		//取得远程数据
		for($j=0;$j<3;$j++)
		{
			$pagetext=ReadFiletext($nextlink);
			if($pagetext)
			{
				break;
			}
		}
		//页面不存在
		if(empty($pagetext))
		{
			continue;
		}
		//替换网页变量
	    $pagetext=RepCjPagetextStr($pagetext,$the_r);
		//替换回车
		$pagetext=ReplaceFc($pagetext);
		$newstext=ReturnCJ_str($newstextzz,"newstext",$pagetext);
		if($newstext)
		{
			$allpagetext.=$addpagetag.$newstext;
		}
	}
	return $allpagetext;
}

//采集时间格式转换
function CjFormatNewstime($newstime){
	$newstime=str_replace(array('年','月','日','.','时','分','秒','/'),array('-','-','','-',':',':','','-'),$newstime);
	return $newstime;
}

//采集信息文件
function GetNewsInfo($classid,$checkrnd,$start,$userid,$username){
	global $empire,$class_r,$fun_r,$dbtbpre;
	$userid=(int)$userid;
	$classid=(int)$classid;
	$start=(int)$start;
	if(empty($classid)||empty($checkrnd))
	{printerror("FailCX","ListInfoClass.php");}
	//验证权限
	CheckLevel($userid,$username,$classid,"cj");
	$r=$empire->fetch1("select * from {$dbtbpre}enewsinfoclass where classid='$classid'");
	//副表
	$ra=$empire->fetch1("select * from {$dbtbpre}ecms_infoclass_".$r[tbname]." where classid='$classid'");
	//组合两数组
	$r=TogTwoArray($r,$ra);
	//导入编码文件
	if($r['enpagecode'])
	{
		@include_once(ECMS_PATH."e/class/doiconv.php");
	}
	//取得模型
	$record="<!--record-->";
	$field="<!--field--->";
	$mr=$empire->fetch1("select cj,tid,tbname from {$dbtbpre}enewsmod where mid='".$class_r[$r[newsclassid]][modid]."'");
	$cjr=explode($record,$mr[cj]);
	$count=count($cjr);
	if(empty($start))
	{$start=0;}
	$b=0;
	$sql=$empire->query("select linkid,newsurl,titlepic from {$dbtbpre}enewslinktmp where checkrnd='$checkrnd' and linkid>".$start." order by linkid limit ".$r[renum]);
	//采集时间
	$newstime=date("Y-m-d H:i:s");
    $truetime=time();
	$tmptime=$newstime;
	while($nr=$empire->fetch($sql))
	{
		$b=1;
		$newstart=$nr[linkid];
		//入库数据库是否有记录
		if(empty($r[recjtheurl]))
		{
			$tmpnum=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_infotmp_".$r[tbname]." where oldurl='$nr[newsurl]' limit 1");
			if($tmpnum)
			{continue;}
		}
		//取得远程页面，三次取不到值的将不取值
		for($i=1;$i<=3;$i++)
		{
			$info=ReadFiletext($nr[newsurl]);
			if(!empty($info))
			{
				break;
			}
		}
		if(empty($info))
		{continue;}
		//替换网页变量
	    $info=RepCjPagetextStr($info,$r);
		//替换回车
		$info=ReplaceFc($info);
		//-----------------
		$ifield="";
		$ivalue="";
		$next=0;
		for($c=0;$c<$count-1;$c++)
		{
			$zzvalue="";
			$cjr1=explode($field,$cjr[$c]);
			$dofield=$cjr1[1];
			$var="zz_".$dofield;
			$var1="z_".$dofield;
			$var2="qz_".$dofield;
			$var3="save_".$dofield;
			//标题图片
			if($dofield=="titlepic")
			{
				if($nr[titlepic])
				{
					$zzvalue=$nr[titlepic];
					$ifield.=",".$dofield;
			        $ivalue.=",'".addslashes($zzvalue)."'";
					continue;
				}
			}
			//图片集
			if($dofield=="morepic"&&$r[$var])
			{
				//替换下载链接
	            $text=stripSlashes(stripSlashes($r[$var]));
				//替换回车
				$text=ReplaceFc($text);
				$down=explode("[!empirecms!]",$text);
				//小图
	            $zztext=RepInfoZZ($down[0],"ecmsspicurl",0);
	            $strtext=GetInfoStr($down[0],"ecmsspicurl",1);
	            $text1=stripSlashes(preg_replace($zztext,$strtext,$info));
				//大图
				if($down[1])
				{
					$zztext=RepInfoZZ($down[1],"ecmsbpicurl",0);
	                $strtext=GetInfoStr($down[1],"ecmsbpicurl",1);
	                $text2=stripSlashes(preg_replace($zztext,$strtext,$info));
				}
				//名称
				if($down[2])
				{
					$zztext=RepInfoZZ($down[2],"ecmspicname",0);
	                $strtext=GetInfoStr($down[2],"ecmspicname",1);
	                $text3=stripSlashes(preg_replace($zztext,$strtext,$info));
				}
				$zzvalue=GetCjMorepicpath($text1,$text2,$text3,"ecmsspicurl","ecmsbpicurl","ecmspicname",$r[$var2]);
				$ifield.=",".$dofield;
			    $ivalue.=",'".addslashes($zzvalue)."'";
				continue;
			}
			//下载地址
			if($dofield=="downpath"&&$r[$var])
			{
				//替换下载链接
	            $text=stripSlashes(stripSlashes($r[$var]));
				//替换回车
				$text=ReplaceFc($text);
				$down=explode("[!empirecms!]",$text);
				//地址
	            $zztext=RepInfoZZ($down[0],"ecmsdownpathurl",0);
	            $strtext=GetInfoStr($down[0],"ecmsdownpathurl",1);
	            $text1=stripSlashes(preg_replace($zztext,$strtext,$info));
				//名称
				if($down[1])
				{
					$zztext=RepInfoZZ($down[1],"ecmsdownpathname",0);
	                $strtext=GetInfoStr($down[1],"ecmsdownpathname",1);
	                $text2=stripSlashes(preg_replace($zztext,$strtext,$info));
				}
				$zzvalue=GetCjDownpath($text1,$text2,"ecmsdownpathurl","ecmsdownpathname",$r[$var2],0);
				$ifield.=",".$dofield;
			    $ivalue.=",'".addslashes($zzvalue)."'";
				continue;
			}
			//在线地址
			if($dofield=="onlinepath"&&$r[$var])
			{
				//替换下载链接
	            $text=stripSlashes(stripSlashes($r[$var]));
				//替换回车
				$text=ReplaceFc($text);
				$down=explode("[!empirecms!]",$text);
				//地址
	            $zztext=RepInfoZZ($down[0],"ecmsonlinepathurl",0);
	            $strtext=GetInfoStr($down[0],"ecmsonlinepathurl",1);
	            $text1=stripSlashes(preg_replace($zztext,$strtext,$info));
				//名称
				if($down[1])
				{
					$zztext=RepInfoZZ($down[1],"ecmsonlinepathname",0);
	                $strtext=GetInfoStr($down[1],"ecmsonlinepathname",1);
	                $text2=stripSlashes(preg_replace($zztext,$strtext,$info));
				}
				$zzvalue=GetCjDownpath($text1,$text2,"ecmsonlinepathurl","ecmsonlinepathname",$r[$var2],1);
				$ifield.=",".$dofield;
			    $ivalue.=",'".addslashes($zzvalue)."'";
				continue;
			}
			if(empty($r[$var1]))
			{
				if($r[$var])
				{
					$zzvalue=ReturnCJ_str($r[$var],$dofield,$info);
					if($zzvalue)
					{
						$zzvalue=$r[$var2].$zzvalue;
				    }
				}
			}
			else
			{$zzvalue=$r[$var1];}
			//------------------------------信息时间
			if($dofield=="newstime")
			{
				$newstime=$zzvalue;
				if(empty($newstime))
				{
					$newstime=$tmptime;
				}
				else
				{
					$newstime=CjFormatNewstime($newstime);//时间转换
				}
				continue;
			}
			//------------------------------信息来源
			if($dofield=="befrom"||$dofield=="writer")
			{
				//标题去除html代码
		        $zzvalue=strip_tags(str_replace("\r\n","",$zzvalue));
			}
			//------------------------------标题
			if($dofield=="title")
			{
				//标题去除html代码
		        $zzvalue=strip_tags(str_replace("\r\n","",$zzvalue));
				if(empty($zzvalue))
				{
					$next=1;
					break;
				}
				$keyboard=sub($zzvalue,0,$r[keynum],false);
				//标题是否包含关键字
				if($r[keyboard])
				{
					$t=HaveKeyboard($zzvalue,$r[keyboard]);
					if(empty($t))
					{
						$next=1;
						break;
					}
				}
				if($r[retitlewriter])//标题完全一样
				{
					//入库比较
					$onum=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_".$class_r[$r[newsclassid]][tbname]." where title='".addslashes($zzvalue)."' and classid='$r[newsclassid]' limit 1");
					if($onum)
					{
						$next=1;
						break;
					}
					/*采集库比较
					$onum=$empire->num("select id from {$dbtbpre}ecms_infotmp_".$r[tbname]." where title='".addslashes($zzvalue)."' limit 1");
					if($onum)
					{
						$next=1;
						break;
					}
					*/
				}
				if($r[titlelen])//标题相似
				{
					//入库比较
					$c_title=addslashes(sub($zzvalue,0,$r[titlelen],false));
					$onum=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_".$class_r[$r[newsclassid]][tbname]." where title like '%$c_title%' and classid='$r[newsclassid]' limit 1");
					if($onum)
					{
						$next=1;
						break;
					}
					/*采集比较
					$onum=$empire->num("select id from {$dbtbpre}ecms_infotmp_".$r[tbname]." where title like '%$c_title%' limit 1");
					if($onum)
					{
						$next=1;
						break;
					}
					*/
				}
			}
			//新闻内容分页
			if($dofield=="newstext")
			{
				//是否有分页
				if($r[pagezz]||$r[pageallzz])
				{
					//上下页式
					if(empty($r[pagetype]))
					{
						$zzvalue.=GetMoreCjPagetext($nr[newsurl],$r[$var],$r[smallpagezz],$r[pagezz],$r[pagetype],$info,$r);
					}
					//全部列表式
					else
					{
						$zzvalue.=GetMoreCjPagetextall($nr[newsurl],$r[$var],$r[smallpageallzz],$r[pageallzz],$r[pagetype],$info,$r);
					}
				}
			}
			//替换关键字
			if($dofield=="title"||$dofield=="newstext")
			{
				$zzvalue=RepInfoWord($zzvalue,$r[oldword],$r[newword]);
			}
			//新闻内容
			if($dofield=="newstext")
			{
				$zzvalue=RepAd($r[repad],$zzvalue);
				if($r['newstextisnull']==1&&empty($zzvalue))
				{
					$next=1;
					break;
				}
			}

			$ifield.=",".$dofield;
			$ivalue.=",'".addslashes($zzvalue)."'";
		}
		if($next)
		{continue;}
		//入临时库
		$isql=$empire->query("insert into {$dbtbpre}ecms_infotmp_".$r[tbname]."(classid,oldurl,checked,keyboard,newstime,truetime,tmptime,userid,username".$ifield.") values($classid,'$nr[newsurl]',0,'".addslashes($keyboard)."','$newstime',$truetime,'$tmptime',$userid,'".addslashes($username)."'".$ivalue.");");
    }
	//采集结束
	if(empty($b))
	{
		//删除记录
		$del=$empire->query("delete from {$dbtbpre}enewslinktmp where checkrnd='$checkrnd'");
		//更新最后时间
		$ucjsql=$empire->query("update {$dbtbpre}enewsinfoclass set lasttime='".time()."' where classid='$classid'");
		//自动入库
		if($r['justloadin'])
		{
			echo $fun_r['cjLoadInInfos']."<script>self.location.href='enews.php?enews=CjNewsIn_all&classid=$classid&checked=$r[justloadcheck]&fm=1';</script>";
			exit();
		}
		//单个节点
		if(getcvar('recjnum')==1)
		{
			echo"<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><font color=red>".$fun_r['CjSuccess']."</font><script>parent.location.href='CheckCj.php?classid=$classid';</script>";
		}
		else
		{
			echo"<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><body topmargin=0><font color=red>".$r[classname]."  ".$fun_r['CjSuccess']."</font>,  <input type=button name=button value='".$fun_r['OnlickLoadInCj']."' onclick=\"window.open('CheckCj.php?classid=$classid');\">";
			echo"<script>parent.checkrecj.location.href='CheckReCj.php';</script></body>";
		}
		exit();
	}
	//echo"(ID:<font color=red><b>".$newstart."</b></font>)<script>self.location.href='enews.php?enews=GetNewsInfo&checkrnd=$checkrnd&classid=$classid&start=$newstart';</script>";
	echo"<meta http-equiv=\"refresh\" content=\"".$r['keeptime'].";url=enews.php?enews=GetNewsInfo&checkrnd=$checkrnd&classid=$classid&start=$newstart\">".$r[classname]." (ID:<font color=red><b>".$newstart."</b></font>)";
	exit();
}

//#################单个采集文件预览################
function ViewGetNewsInfo($classid,$newspage,$userid,$username){
	global $empire,$class_r,$fun_r,$dbtbpre;
	$classid=(int)$classid;
	if(empty($classid)||empty($newspage))
	{printerror("FailCX","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"cj");
	$r=$empire->fetch1("select * from {$dbtbpre}enewsinfoclass where classid='$classid'");
	if(empty($r[classid]))
	{printerror("FailCX","history.go(-1)");}
	//副表
	$ra=$empire->fetch1("select * from {$dbtbpre}ecms_infoclass_".$r[tbname]." where classid='$classid'");
	//组合两数组
	$r=TogTwoArray($r,$ra);
	//导入编码文件
	if($r['enpagecode'])
	{
		@include_once("doiconv.php");
	}
	//取得模型
	$record="<!--record-->";
	$field="<!--field--->";
	$mr=$empire->fetch1("select cj from {$dbtbpre}enewsmod where mid='".$class_r[$r[newsclassid]][modid]."'");
	$cjr=explode($record,$mr[cj]);
	$count=count($cjr);
	//采集时间
	$newstime=date("Y-m-d H:i:s");
	//入库数据库是否有记录
	if(empty($r[recjtheurl]))
	{
		$tmpnum=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_infotmp_".$r[tbname]." where oldurl='$newspage' limit 1");
		if($tmpnum)
		{
			echo $fun_r['ReCj'];
			exit();
	    }
	}
	//取得远程页面，三次取不到值的将不取值
	for($i=1;$i<=3;$i++)
	{
		$info=ReadFiletext($newspage);
		if(!empty($info))
		{
			break;
	    }
	}
	if(empty($info))
	{
		echo $fun_r['CanNotOpenUrl'];
		exit();
	}
	//替换网页变量
	$info=RepCjPagetextStr($info,$r);
	//替换回车
	$info=ReplaceFc($info);
	//-----------------
	$ifield="";
	$ivalue="";
	$next=0;
	for($c=0;$c<$count-1;$c++)
	{
		$zzvalue="";
		$cjr1=explode($field,$cjr[$c]);
		$dofield=$cjr1[1];
		$dofieldname=$cjr1[0];
		$var="zz_".$dofield;
		$var1="z_".$dofield;
		$var2="qz_".$dofield;
		$var3="save_".$dofield;
		//图片集
		if($dofield=="morepic"&&$r[$var])
		{
			//替换下载链接
	        $text=stripSlashes(stripSlashes($r[$var]));
			//替换回车
			$text=ReplaceFc($text);
			$down=explode("[!empirecms!]",$text);
			//小图
	        $zztext=RepInfoZZ($down[0],"ecmsspicurl",0);
	        $strtext=GetInfoStr($down[0],"ecmsspicurl",1);
	        $text1=stripSlashes(preg_replace($zztext,$strtext,$info));
			//大图
			if($down[1])
			{
				$zztext=RepInfoZZ($down[1],"ecmsbpicurl",0);
	            $strtext=GetInfoStr($down[1],"ecmsbpicurl",1);
	            $text2=stripSlashes(preg_replace($zztext,$strtext,$info));
			}
			//名称
			if($down[2])
			{
				$zztext=RepInfoZZ($down[2],"ecmspicname",0);
	            $strtext=GetInfoStr($down[2],"ecmspicname",1);
	            $text3=stripSlashes(preg_replace($zztext,$strtext,$info));
			}
			$zzvalue=GetCjMorepicpath($text1,$text2,$text3,"ecmsspicurl","ecmsbpicurl","ecmspicname",$r[$var2]);
			$data.="<tr><td><b>".$dofieldname."<br>(".$dofield.")</b></td><td>".$zzvalue."</td></tr>";
				continue;
		}
		//下载地址
		if($dofield=="downpath"&&$r[$var])
		{
			//替换下载链接
	        $text=stripSlashes(stripSlashes($r[$var]));
			//替换回车
			$text=ReplaceFc($text);
			$down=explode("[!empirecms!]",$text);
			//地址
	        $zztext=RepInfoZZ($down[0],"ecmsdownpathurl",0);
	        $strtext=GetInfoStr($down[0],"ecmsdownpathurl",1);
	        $text1=stripSlashes(preg_replace($zztext,$strtext,$info));
			//名称
			if($down[1])
			{
				$zztext=RepInfoZZ($down[1],"ecmsdownpathname",0);
	            $strtext=GetInfoStr($down[1],"ecmsdownpathname",1);
	            $text2=stripSlashes(preg_replace($zztext,$strtext,$info));
			}
			$zzvalue=GetCjDownpath($text1,$text2,"ecmsdownpathurl","ecmsdownpathname",$r[$var2],0);
			$data.="<tr><td><b>".$dofieldname."<br>(".$dofield.")</b></td><td>".$zzvalue."</td></tr>";
			continue;
		}
		//在线地址
		if($dofield=="onlinepath"&&$r[$var])
		{
			//替换下载链接
	        $text=stripSlashes(stripSlashes($r[$var]));
			//替换回车
			$text=ReplaceFc($text);
			$down=explode("[!empirecms!]",$text);
			//地址
	        $zztext=RepInfoZZ($down[0],"ecmsonlinepathurl",0);
	        $strtext=GetInfoStr($down[0],"ecmsonlinepathurl",1);
	        $text1=stripSlashes(preg_replace($zztext,$strtext,$info));
			//名称
			if($down[1])
			{
				$zztext=RepInfoZZ($down[1],"ecmsonlinepathname",0);
	            $strtext=GetInfoStr($down[1],"ecmsonlinepathname",1);
	            $text2=stripSlashes(preg_replace($zztext,$strtext,$info));
			}
			$zzvalue=GetCjDownpath($text1,$text2,"ecmsonlinepathurl","ecmsonlinepathname",$r[$var2],1);
			$data.="<tr><td><b>".$dofieldname."<br>(".$dofield.")</b></td><td>".$zzvalue."</td></tr>";
			continue;
		}

		if(empty($r[$var1]))
		{
			if($r[$var])
			{
				$zzvalue=ReturnCJ_str($r[$var],$dofield,$info);
				if($zzvalue)
				{
					$zzvalue=$r[$var2].$zzvalue;
				}
			}
		}
		else
		{$zzvalue=$r[$var1];}
		//------------------------------信息来源
		if($dofield=="befrom"||$dofield=="writer")
		{
			//标题去除html代码
		    $zzvalue=strip_tags(str_replace("\r\n","",$zzvalue));
		}
		//------------------------------标题
		if($dofield=="title")
		{
			//标题去除html代码
		    $zzvalue=strip_tags(str_replace("\r\n","",$zzvalue));
			if(empty($zzvalue))
			{
				echo $fun_r['CjEmptyTitle'];
			    exit();
			}
			//标题是否包含关键字
			if($r[keyboard])
			{
				$t=HaveKeyboard($zzvalue,$r[keyboard]);
		        if(empty($t))
			    {
					echo $fun_r['CjTitleKey'];
			        exit();
		        }
			}
			if($r[retitlewriter])//标题完全一样
		    {
			   //入库比较
			   $onum=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_".$class_r[$r[newsclassid]][tbname]." where title='".addslashes($zzvalue)."' and classid='$r[newsclassid]' limit 1");
			   if($onum)
			   {
					echo $fun_r['CjReTitleWriter'];
					exit();
			   }
				/*采集库比较
				$onum=$empire->num("select id from {$dbtbpre}ecms_infotmp_".$r[tbname]." where title='".addslashes($zzvalue)."' limit 1");
				if($onum)
				{
					echo $fun_r['CjReTitleWriter'];
					exit();
				}
				*/
		    }
		    if($r[titlelen])//标题相似
		    {
			  //入库比较
			  $c_title=addslashes(sub($zzvalue,0,$r[titlelen],false));
			  $onum=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_".$class_r[$r[newsclassid]][tbname]." where title like '%$c_title%' and classid='$r[newsclassid]' limit 1");
			  if($onum)
			  {
				echo $fun_r['CjSingTitlelen'].$r[titlelen].$fun_r['CjSingTitlelenL'];
				exit();
			  }
			  /*采集比较
			  $onum=$empire->num("select id from {$dbtbpre}ecms_infotmp_".$r[tbname]." where title like '%$c_title%' limit 1");
			  if($onum)
			  {
				echo $fun_r['CjSingTitlelen'].$r[titlelen].$fun_r['CjSingTitlelenL'];
				exit();
			  }
			  */
		    }
		}
		//新闻内容分页
		if($dofield=="newstext")
		{
			//是否有分页
			if($r[pagezz]||$r[pageallzz])
			{
				//上下页式
				if(empty($r[pagetype]))
				{
					$zzvalue.=GetMoreCjPagetext($newspage,$r[$var],$r[smallpagezz],$r[pagezz],$r[pagetype],$info,$r);
				}
				//全部列表式
				else
				{
					$zzvalue.=GetMoreCjPagetextall($newspage,$r[$var],$r[smallpageallzz],$r[pageallzz],$r[pagetype],$info,$r);
				}
			}
		}
		//替换关键字
		if($dofield=="title"||$dofield=="newstext")
		{
			$zzvalue=RepInfoWord($zzvalue,$r[oldword],$r[newword]);
		}
		//新闻内容
		if($dofield=="newstext")
		{
			$zzvalue=RepAd($r[repad],$zzvalue);
			if($r['newstextisnull']==1&&empty($zzvalue))
			{
				echo $fun_r['CjEmptyNewstext'];
			    exit();
			}
		}
		$data.="<tr><td><b>".$dofieldname."<br>(".$dofield.")</b></td><td>".$zzvalue."</td></tr>";
	}
	//输出数据
	$data="<table width='96%' border=1 align=center cellpadding=3 cellspacing=0>
  <tr><td width=30% align=center><b>VAR</b></td><td align=center><b>GET</b></td></tr><tr><td><b>".$fun_r['ViewCjPage']."</b></td><td><a href='".$newspage."' target=_blank>".$newspage."</a></td></tr>".$data."</table>";
	echo $data;
	exit();
}

//是否有关键字
function HaveKeyboard($title,$keyboard) {
	$r=explode(",",$keyboard);
	$b=0;
	for($i=0;$i<count($r);$i++)
	{
		$cr=explode($r[$i],$title);
		if(count($cr)<>1)
		{
			$b=1;
			break;
		}
	}
	return $b;
}

//替换关键字
function RepInfoWord($title,$oldword,$newword){
	if(empty($oldword))
	{
		return $title;
	}
	$oldword=stripSlashes($oldword);
	$newword=stripSlashes($newword);
	//替换回车
	$oldword=ReplaceFc($oldword);
	$newword=ReplaceFc($newword);
	$repmore=0;
	if(strstr($newword,","))
	{
		$repmore=1;
		$nr=explode(",",$newword);
	}
	$r=explode(",",$oldword);
	for($i=0;$i<count($r);$i++)
	{
		//替换多项
		if($repmore)
		{
			$title=str_replace($r[$i],$nr[$i],$title);
		}
		else
		{
			$title=str_replace($r[$i],$newword,$title);
		}
	}
	return $title;
}

//去掉单引号
function RepDyh($text){
	//$text=str_replace("\'","\\\'",stripSlashes($text));
	$text=addslashes(stripSlashes($text));
	return $text;
}

//补零
function AddNumZero($no,$endno){
	$len=strlen($endno);
	$forlen=$len-strlen($no);
	for($i=1;$i<=$forlen;$i++)
	{
		$no="0".$no;
	}
	return $no;
}

//替换标签
function RepBq($indextext){
	global $empire,$dbtbpre;
	$sql=$empire->query("select bq,funname from {$dbtbpre}enewsbq where isclose=0 order by bqid");
	while($r=$empire->fetch($sql))
	{
        $preg_str="/\[".$r[bq]."\](.+?)\[\/".$r[bq]."\]/is";
		$indextext=preg_replace($preg_str,"<? @".$r[funname]."(\\1);?>",$indextext);
	}
	return $indextext;
}

//替换灵动标签
function DoRepEcmsLoopBq($temp){
	$yzz="/\[e:loop={(.+?)}\](.+?)\[\/e:loop\]/is";
	$xzz="<?php
\$bqno=0;
\$ecms_bq_sql=sys_ReturnEcmsLoopBq(\\1);
while(\$bqr=\$empire->fetch(\$ecms_bq_sql)){
\$bqsr=sys_ReturnEcmsLoopStext(\$bqr);
\$bqno++;
?>\\2<?php
}
?>";
	return preg_replace($yzz,$xzz,$temp);;
}

//生成打印页面
function GetPrintPage(){
	global $empire,$dbtbpre,$fun_r;
	$file="../data/template/printtemp.php";
	$string=ReadFiletext($file);
	$r=$empire->fetch1("select printtemp from ".GetTemptb("enewspubtemp")." limit 1");
	$r[printtemp]=ReplaceTempvar($r[printtemp]);//公共模板变量
	$r[printtemp]=str_replace("[!--pagetitle--]",$fun_r['PrintPage'],$r[printtemp]);
	$printtemp=RepPrintTempV($r[printtemp]);
	$string=str_replace("<!--empire.print-->",$printtemp,$string);
	$truefile="../DoPrint/index.php";
	WriteFiletext($truefile,$string);
}

//替换打印模板变量
function RepPrintTempV($temptext){
	$temptext=str_replace("[!--id--]","<?=\$r[id]?>",$temptext);
	$temptext=str_replace("[!--classid--]","<?=\$r[classid]?>",$temptext);
	$temptext=str_replace("[!--title--]","<?=\$r[title]?>",$temptext);
	$temptext=str_replace("[!--writer--]","<?=\$r[writer]?>",$temptext);
	$temptext=str_replace("[!--newstime--]","<?=\$r[newstime]?>",$temptext);
	$temptext=str_replace("[!--befrom--]","<?=\$r[befrom]?>",$temptext);
	$temptext=str_replace("[!--newstext--]","<?=\$r[newstext]?>",$temptext);
	$temptext=str_replace("[!--smalltext--]","<?=\$r[smalltext]?>",$temptext);
	$temptext=str_replace("[!--username--]","<?=\$r[username]?>",$temptext);
	$temptext=str_replace("[!--titlelink--]","<?=\$titlelink?>",$temptext);
	$temptext=str_replace("[!--url--]","<?=\$url?>",$temptext);
	return $temptext;
}

//取得栏目目录名称
function GetPathname($classname){
	$c=explode("/",$classname);
	$count=count($c)-1;
	$cr[0]=$c[$count];//栏目目录名
	$len=strlen($cr[0]);
	//上级栏目目录名
	$cr[1]=substr($classname,0,strlen($classname)-$len);
	return $cr;
}

//更新缓存
function ChangeEnewsData($userid,$username){
	//操作权限
	CheckLevel($userid,$username,$classid,"changedata");
	//更新参数设置
	GetConfig();
	//更新类别
	GetClass();
	//更新会员组
	GetMemberLevel();
	//操作日志
	insert_dolog("");
	printerror("ChangeDataSuccess","history.go(-1)");
}

//########################远程发布#############
//目录转向
function FtpChPath($fid,$r){
	$path=$r[ftppath]."/e/ftp";
	@ftp_chdir($fid,$path);
}

//上传ftp目录
function FtpTranPath($ftpid,$ldir,$hdir){
	$r=ReturnFtpInfo($ftpid);
	$e=new enews_ftp();
    $fid=$e->fconnect($r[ftphost],$r[ftpport]);
    $e->fLogin($fid,$r[ftpusername],$r[ftppassword]);
	FtpChPath($fid,$r);
    //上传目录
    $e->ftp_copy($fid,$ldir,$hdir,$r[ftpmode]);
    $e->fexit($fid);
}

//-------------删除ftp目录
function FtpDelPath($ftpid,$dir){
	$r=ReturnFtpInfo($ftpid);
	$e=new enews_ftp();
    $fid=$e->fconnect($r[ftphost],$r[ftpport]);
    $e->fLogin($fid,$r[ftpusername],$r[ftppassword]);
	FtpChPath($fid,$r);
    //删除目录
    $e->ftp_rmAll($fid,$dir);
    $e->fexit($fid);
}

//删除ftp文件
function FtpDelFile($ftpid,$fr){
	$r=ReturnFtpInfo($ftpid);
    $e=new enews_ftp();
    $fid=$e->fconnect($r[ftphost],$r[ftpport]);
    $e->fLogin($fid,$r[ftpusername],$r[ftppassword]);
	FtpChPath($fid,$r);
    //删除文件
	for($i=0;$i<count($fr);$i++)
	{
		$e->fDelFile($fid,$fr[$i]);
	}
    $e->fexit($fid);
}

//上传文件
function FtpTranFile($ftpid,$fr,$fr1){
	$r=ReturnFtpInfo($ftpid);
    $e=new enews_ftp();
    $fid=$e->fconnect($r[ftphost],$r[ftpport]);
    $e->fLogin($fid,$r[ftpusername],$r[ftppassword]);
	FtpChPath($fid,$r);
    //删除文件
	for($i=0;$i<count($fr);$i++)
	{
		$e->fTranFile($fid,$fr[$i],$fr1[$i],$r[ftpmode]);
	}
    $e->fexit($fid);
}

//建立ftp目录
function FtpMkdir($ftpid,$pr,$mod){
	$r=ReturnFtpInfo($ftpid);
	$e=new enews_ftp();
    $fid=$e->fconnect($r[ftphost],$r[ftpport]);
    $e->fLogin($fid,$r[ftpusername],$r[ftppassword]);
	FtpChPath($fid,$r);
	for($i=0;$i<count($pr);$i++)
	{
		if(!@ftp_chdir($fid,$pr[$i]))
		{
			$e->fMkdir($fid,$pr[$i]);
			if($mod)
			{
				$e->fChmoddir($fid,$mod,$pr[$i]);
			}
		}
	}
    $e->fexit($fid);
}

//返回ftp信息
function ReturnFtpInfo($ftpid){
	global $empire,$dbtbpre;
	$r=$empire->fetch1("select * from {$dbtbpre}enewspublic limit 1");
	return $r;
}

//初使化发布任务
function AddPostUrlData($postdata,$userid,$username){
	global $empire,$fun_r,$dbtbpre;
	$count=count($postdata);
	if(empty($count))
	{printerror("NotPostData","history.go(-1)");}
	//操作权限
	CheckLevel($userid,$username,$classid,"postdata");
	$e="!!!";
	$rnd=md5(uniqid(microtime()));
	for($i=0;$i<$count;$i++)
	{
		$r=explode($e,$postdata[$i]);
		$r[1]=(int)$r[1];
		$sql=$empire->query("insert into {$dbtbpre}enewspostdata(rnd,postdata,ispath) values('$rnd','$r[0]',$r[1]);");
    }
	$line=(int)$_POST['line'];
	if($line==0)
	{
		$line=10;
	}
	echo $fun_r[AddPostDataSuccess]."<script>self.location.href='enews.php?enews=PostUrlData&start=0&line=$line&rnd=$rnd';</script>";
	exit();
}

//远程发布
function PostUrlData($start,$rnd,$userid,$username){
	global $empire,$fun_r,$dbtbpre,$incftp;
	if(empty($rnd))
	{printerror("FailCX","history.go(-1)");}
	//链接FTP
	if(empty($incftp))
	{
		@include(ECMS_PATH."e/class/ftp.php");
	}
	$pr=ReturnFtpInfo($ftpid);
	$e=new enews_ftp();
    $fid=$e->fconnect($pr['ftphost'],$pr['ftpport']);
    $e->fLogin($fid,$pr['ftpusername'],$pr['ftppassword']);
	FtpChPath($fid,$pr);

	$line=(int)$_GET['line'];//每10个为一组
	$start=(int)$start;
	$b=0;
	$sql=$empire->query("select postid,postdata,ispath from {$dbtbpre}enewspostdata where rnd='$rnd' and postid>$start order by postid limit ".$line);
	while($r=$empire->fetch($sql))
	{
		$b=1;
		$newstart=$r[postid];
		//文件
		if($r[ispath])
		{
			$fr=explode(",",$r[postdata]);
			for($i=0;$i<count($fr);$i++)
			{
				$e->fTranFile($fid,$fr[$i],$fr[$i],$pr[ftpmode]);
			}
		}
		//目录
		else
		{
			$e->ftp_copy($fid,$r[postdata],$r[postdata],$pr[ftpmode]);
		}
	}
	$e->fexit($fid);//关闭ftp
	if(empty($b))
	{
		$sql=$empire->query("delete from {$dbtbpre}enewspostdata where rnd='$rnd'");
		//操作日志
		insert_dolog("");
		printerror("PostDataSuccess","PostUrlData.php");
	}
	echo $fun_r[OnePostDataSuccess]."<script>self.location.href='enews.php?enews=PostUrlData&start=$newstart&line=$line&rnd=$rnd';</script>";
	exit();
}

//替换表单元素长度
function RepFformSize($f,$string,$type,$fformsize=''){
	$fformsize=ReturnDefFformSize($f,$type,$fformsize);
	if($type=='textarea')
	{
		$r=explode(',',$fformsize);
		$string=str_replace('[!--fsize.w--]',$r[0],$string);
		$string=str_replace('[!--fsize.h--]',$r[1],$string);
	}
	else
	{
		$string=str_replace('[!--fsize.w--]',$fformsize,$string);
	}
	return $string;
}

//返回默认长度
function ReturnDefFformSize($f,$type,$fformsize){
	if(empty($fformsize))
	{
		if($type=='textarea')
		{
			$fformsize='60,10';
		}
		elseif($type=='img')
		{
			$fformsize='45';
		}
		elseif($type=='file')
		{
			$fformsize='45';
		}
		elseif($type=='flash')
		{
			$fformsize='45';
		}
		elseif($type=='date')
		{
			$fformsize='12';
		}
		elseif($type=='color')
		{
			$fformsize='10';
		}
		elseif($type=='linkfield')
		{
			$fformsize='45';
		}
		elseif($type=='downpath')
		{
			$fformsize='45';
		}
		elseif($type=='onlinepath')
		{
			$fformsize='45';
		}
	}
	return $fformsize;
}

//取得select/radio元素代码
function GetFformSelect($type,$f,$fvalue,$fformsize=''){
	$vr=explode("|",$fvalue);
	$count=count($vr);
	$change="";
	$def=':default';
	for($i=0;$i<$count;$i++)
	{
		$val=$vr[$i];
		$isdef="";
		if(strstr($val,$def))
		{
			$dr=explode($def,$val);
			$val=$dr[0];
			$isdef="||\$ecmsfirstpost==1";
		}
		if($type=='select')
		{
			$change.="<option value=\"".$val."\"<?=\$r[".$f."]==\"".$val."\"".$isdef."?' selected':''?>>".$val."</option>";
		}
		elseif($type=='checkbox')
		{
			$change.="<input name=\"".$f."[]\" type=\"checkbox\" value=\"".$val."\"<?=strstr(\$r[".$f."],\"|".$val."|\")".$isdef."?' checked':''?>>".$val;
		}
		else
		{
			$change.="<input name=\"".$f."\" type=\"radio\" value=\"".$val."\"<?=\$r[".$f."]==\"".$val."\"".$isdef."?' checked':''?>>".$val;
		}
	}
	if($type=="select")
	{
		if($fformsize)
		{
			$addsize=' style="width:'.$fformsize.'"';
		}
		$change="<select name=\"".$f."\" id=\"".$f."\"".$addsize.">".$change."</select>";
	}
	return $change;
}

//取得表单元素html代码
function GetFform($type,$f,$fvalue,$linkfieldval,$fformsize=''){
	if($type=="select"||$type=="radio"||$type=="checkbox")
	{
		return GetFformSelect($type,$f,$fvalue,$fformsize);
	}
	$file="../data/html/fhtml.php";
	$data=ReadFiletext($file);
	//特殊字段
	if($f=="newstext"||$f=="writer"||$f=="befrom"||$f=="downpath"||$f=="onlinepath"||$f=="morepic"||$f=="playerid")
	{$type=$f;}
	$exp="[!--".$type."--]";
	$r=explode($exp,$data);
	$string=str_replace("[!--enews.var--]",$f,$r[1]);
	$string=str_replace("[!--enews.def.val--]",$fvalue,$string);
	if($type=='linkfield')
	{
		$linkr=explode('.',$linkfieldval);
		$string=str_replace("[!--enews.cfield.var--]",$linkr[1],$string);
		$string=str_replace("[!--enews.ctbname--]",$linkr[0],$string);
	}
	$string=RepFformSize($f,$string,$type,$fformsize);
	return $string;
}

//取得投稿表单元素html代码
function GetQFform($type,$f,$fvalue,$fformsize=''){
	if($type=="select"||$type=="radio"||$type=="checkbox")
	{
		return GetFformSelect($type,$f,$fvalue,$fformsize);
	}
	$file="../data/html/qfhtml.php";
	$data=ReadFiletext($file);
	//特殊字段
	if($f=="newstext"||$f=="downpath"||$f=="onlinepath"||$f=="morepic"||$f=="playerid")
	{$type=$f;}
	$exp="[!--".$type."--]";
	$r=explode($exp,$data);
	$string=str_replace("[!--enews.var--]",$f,$r[1]);
	$string=str_replace("[!--enews.def.val--]",$fvalue,$string);
	$string=RepFformSize($f,$string,$type,$fformsize);
	return $string;
}

//取得会员表单元素html代码
function GetMemberFform($type,$f,$fvalue,$fformsize=''){
	if($type=="select"||$type=="radio"||$type=="checkbox")
	{
		return GetFformSelect($type,$f,$fvalue,$fformsize);
	}
	$file="../data/html/memberfhtml.php";
	$data=ReadFiletext($file);
	$exp="[!--".$type."--]";
	$r=explode($exp,$data);
	$string=str_replace("[!--enews.var--]",$f,$r[1]);
	$string=str_replace("[!--enews.def.val--]",$fvalue,$string);
	$string=RepFformSize($f,$string,$type,$fformsize);
	return $string;
}

//取得采集表单元素html代码
function GetCjform($type,$f){
	$file="../data/html/cjhtml.php";
	$data=ReadFiletext($file);
	//特殊字段
	if($f=="downpath"||$f=="onlinepath"||$f=="morepic"||$f=="playerid")
	{$type=$f;}
	if($type=="password"||$type=="select"||$type=="radio"||$type=="checkbox"||$type=="date"||$type=="color"||$type=="linkfield")
	{
		$type="text";
	}
	$exp="[!--".$type."--]";
	$r=explode($exp,$data);
	$string=str_replace("[!--enews.var--]",$f,$r[1]);
	return $string;
}

//组合存文本
function TogSaveTxtF(){
	global $empire,$dbtbpre;
	$savesql=$empire->query("select f,tbname from {$dbtbpre}enewsf where f='newstext' and savetxt=1");
	$savef=',';
	while($saver=$empire->fetch($savesql))
	{
		$savef.=$saver[tbname].'.'.$saver[f].',';
	}
	$onlysql=$empire->query("select f,tbname from {$dbtbpre}enewsf where isonly=1");
	$onlyf=',';
	while($onlyr=$empire->fetch($onlysql))
	{
		$onlyf.=$onlyr[tbname].'.'.$onlyr[f].',';
	}
	$linksql=$empire->query("select f,tbname,linkfieldval from {$dbtbpre}enewsf where fform='linkfield' and samedata=1 and linkfieldval<>''");
	$linkf='|';
	while($linkr=$empire->fetch($linksql))
	{
		$linkf.=$linkr[tbname].'.'.$linkr[f].','.$linkr[linkfieldval].'|';
	}
	$checkboxsql=$empire->query("select f,tbname from {$dbtbpre}enewsf where fform='checkbox'");
	$checkboxf=',';
	while($checkboxr=$empire->fetch($checkboxsql))
	{
		$checkboxf.=$checkboxr[tbname].'.'.$checkboxr[f].',';
	}
	$psql=$empire->query("update {$dbtbpre}enewspublic set savetxtf='$savef',isonlyf='$onlyf',linkfields='$linkf',checkboxf='$checkboxf' limit 1");
	GetConfig();
}

//返回字段值
function ReturnFvalue($value)
{
	$value=str_replace("\r\n","|",$value);
	return $value;
}

//更新模型表单
function ChangeMForm($mid,$tid,$mtemp){
	global $empire,$dbtbpre;
	$file="../data/html/".$mid.".php";
	$sql=$empire->query("select f,fhtml from {$dbtbpre}enewsf where tid='$tid'");
	while($r=$empire->fetch($sql))
	{
		$mtemp=str_replace("[!--".$r[f]."--]",$r[fhtml],$mtemp);
    }
	WriteFiletext($file,$mtemp);
}

//更新投稿表单
function ChangeQmForm($mid,$tid,$mtemp){
	global $empire,$dbtbpre;
	$file="../data/html/q".$mid.".php";
	$sql=$empire->query("select f,qfhtml from {$dbtbpre}enewsf where tid='$tid'");
	while($r=$empire->fetch($sql))
	{
		$mtemp=str_replace("[!--".$r[f]."--]",$r[qfhtml],$mtemp);
    }
	WriteFiletext($file,$mtemp);
}

//更新采集
function ChangeMCj($mid,$tid,$cj){
	global $empire,$dbtbpre;
	$record="<!--record-->";
	$field="<!--field--->";
	//读取修改采集表单
	$data="<tr><td bgcolor=ffffff>[!--enews.name--]</td><td bgcolor=ffffff>[!--enews.var--]</td></tr>";
	$file1="../data/html/editcj".$mid.".php";
	$file="../data/html/cj".$mid.".php";
	$r=explode($record,$cj);
	for($i=0;$i<count($r)-1;$i++)
	{
		$r1=explode($field,$r[$i]);
		$fr=$empire->fetch1("select cjhtml,fhtml from {$dbtbpre}enewsf where f='$r1[1]' and tid='$tid' limit 1");
		$cjtemp=str_replace("[!--enews.name--]",$r1[0],$fr[cjhtml]);
		$str.=$cjtemp;
		$editcjtemp=str_replace("[!--enews.name--]",$r1[0],$data);
		$editcjtemp=str_replace("[!--enews.var--]",$fr[fhtml],$editcjtemp);
		$editcj.=$editcjtemp;
	}
	WriteFiletext($file,$str);
	WriteFiletext($file1,$editcj);
}

//组合采集项
function TogMCj($cname,$cchange){
	$record="<!--record-->";
	$field="<!--field--->";
	$c="";
	for($i=0;$i<count($cchange);$i++)
	{
		$v=$cchange[$i];
		$name=str_replace($field,"",$cname[$v]);
		$name=str_replace($record,"",$name);
		$c.=$name.$field.$v.$record;
	}
	return $c;
}

//组合投稿项
function TogMqenter($cname,$cqenter){
	$record="<!--record-->";
	$field="<!--field--->";
	$c="";
	for($i=0;$i<count($cqenter);$i++)
	{
		$v=$cqenter[$i];
		$name=str_replace($field,"",$cname[$v]);
		$name=str_replace($record,"",$name);
		$c.=$name.$field.$v.$record;
	}
	return $c;
}

//组合搜索项
function TogMSearch($cname,$schange){
	$c="";
	for($i=0;$i<count($schange);$i++)
	{
		$v=$schange[$i];
		$c.=$v.",";
	}
	if($c)
	{
		$c=",".$c;
	}
	return $c;
}

//组合必填项
function TogMustf($cname,$menter){
	$c="";
	for($i=0;$i<count($menter);$i++)
	{
		$v=$menter[$i];
		$c.=$v.",";
	}
	if($c)
	{
		$c=",".$c;
	}
	return $c;
}

//组合录入项
function TogMEnter($cname,$center,$ltempf,$ptempf,$tid){
	global $empire;
	$f=1;
	$record="<!--record-->";
	$field="<!--field--->";
	$c="";
	$lt="";
	$pt="";
	for($i=0;$i<count($center);$i++)
	{
		$v=$center[$i];
		$name=str_replace($field,"",$cname[$v]);
		$name=str_replace($record,"",$name);
		$c.=$name.$field.$v.$record;
	}
	for($i=0;$i<count($ltempf);$i++)
	{
		$v=$ltempf[$i];
		$name=str_replace($field,"",$cname[$v]);
		$name=str_replace($record,"",$name);
		$lt.=$name.$field.$v.$record;
	}
	for($i=0;$i<count($ptempf);$i++)
	{
		$v=$ptempf[$i];
		$name=str_replace($field,"",$cname[$v]);
		$name=str_replace($record,"",$name);
		$pt.=$name.$field.$v.$record;
	}
	$r[0]=$c;
	$r[1]=$lt;
	$r[2]=$pt;
	return $r;
}

//返回自动生成录入表单模板
function ReturnMtemp($cname,$center){
	$temp="<tr><td width='16%' height=25 bgcolor='ffffff'>enews.name</td><td bgcolor='ffffff'>[!--enews.var--]</td></tr>";
	$ntemp="<tr><td height=25 colspan=2 bgcolor='ffffff'><div align=left>enews.name</div></td></tr></table><div style='background-color:#D0D0D0'>[!--enews.var--]</div><table width='100%' align=center cellpadding=3 cellspacing=1 bgcolor='#DBEAF5'>";
	for($i=0;$i<count($center);$i++)
	{
		$v=$center[$i];
		if($v=="newstext")
		{
			$data.=str_replace("enews.var",$v,str_replace("enews.name",$cname[$v],$ntemp));
			continue;
		}
		$data.=str_replace("enews.var",$v,str_replace("enews.name",$cname[$v],$temp));
    }
	return "<table width='100%' align=center cellpadding=3 cellspacing=1 bgcolor='#DBEAF5'>".$data."</table>";
}

//返回自动生成投稿表单模板
function ReturnQmtemp($cname,$cqenter){
	$temp="<tr><td width='16%' height=25 bgcolor='ffffff'>enews.name</td><td bgcolor='ffffff'>[!--enews.var--]</td></tr>";
	$ntemp="<tr><td height=25 colspan=2 bgcolor='ffffff'><div align=left>enews.name</div></td></tr></table><div style='background-color:#D0D0D0'>[!--enews.var--]</div><table width='100%' align=center cellpadding=3 cellspacing=1 bgcolor='#DBEAF5'>";
	for($i=0;$i<count($cqenter);$i++)
	{
		$v=$cqenter[$i];
		if($v=="newstext")
		{
			$data.=str_replace("enews.var",$v,str_replace("enews.name",$cname[$v],$ntemp));
			continue;
		}
		$data.=str_replace("enews.var",$v,str_replace("enews.name",$cname[$v],$temp));
    }
	return "<table width=100% align=center cellpadding=3 cellspacing=1 bgcolor=#DBEAF5>".$data."</table>";
}

//返回附件字段
function ReturnMFileF($enter,$tbname,$tid,$fform="file"){
	global $empire;
	$record="<!--record-->";
	$field="<!--field--->";
	if($tid)
	{
		$a=" and tid='$tid'";
	}
	$f=",";
	$sql=$empire->query("select f from ".$tbname." where fform='$fform'".$a);
	while($r=$empire->fetch($sql))
	{
		if(strstr($enter,$field.$r[f].$record))
		{
			$f.=$r[f].",";
		}
	}
	return $f;
}

//返回br项
function ReturnMTobrF($enter,$tid,$dof="tobr"){
	global $empire,$dbtbpre;
	$record="<!--record-->";
	$field="<!--field--->";
	$f=",";
	$sql=$empire->query("select f from {$dbtbpre}enewsf where ".$dof."=0 and tid='$tid'");
	while($r=$empire->fetch($sql))
	{
		if(strstr($enter,$field.$r[f].$record))
		{
			$f.=$r[f].",";
		}
	}
	return $f;
}

//验证必填项
function ChMustAddF($f,$value,$chf){
	if(strstr($chf,",".$f.","))
	{
		if(!trim($value))
		{
			$GLOBALS['msgmustf']=$f;
			printerror("EmptyMustF","history.go(-1)");
		}
	}
}

//验证唯一项
function ChIsOnlyAddF($id,$tbname,$f,$value,$isq=0){
	global $empire,$public_r,$dbtbpre;
	if(strstr($public_r['isonlyf'],','.$tbname.'.'.$f.','))
	{
		if($id)
		{
			$and=" and id<>$id";
		}
		$num=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_".$tbname." where ".$f."='".addslashes($value)."'".$and." limit 1");
		if($num)
		{
			$GLOBALS['msgisonlyf']=$f;
			if($isq==1)
			{
				printerror("ReIsOnlyF","history.go(-1)",1);
			}
			else
			{
				printerror("ReIsOnlyF","history.go(-1)");
			}
		}
	}
}

//数据同步
function SameDataAddF($id,$classid,$tbname,$f,$value){
	global $empire,$public_r,$dbtbpre;
	if(strstr($public_r['linkfields'],','.$tbname.'.'.$f.'|'))
	{
		$value=addslashes($value);
		$r=$empire->fetch1("select ".$f." from {$dbtbpre}ecms_".$tbname." where id='$id' limit 1");
		if($r[$f]<>$value)
		{
			$tbr=ReturnSameDataTb($tbname,$f);
			if($tbr[0]&&$tbr[1])
			{
				$empire->query("update {$dbtbpre}ecms_".$tbr[0]." set ".$tbr[1]."='$value' where ".$tbr[1]."='$r[$f]'");
			}
		}
	}
}

//返回数据同频表与字段名
function ReturnSameDataTb($tbname,$f){
	global $public_r;
	$expr=explode(','.$tbname.'.'.$f.'|',$public_r['linkfields']);
	$expr1=explode('|',$expr[0]);
	$count=count($expr1)-1;
	$tbr=explode('.',$expr1[$count]);
	return $tbr;
}

//自定义字段返回模板字段处理
function doReturnAddTempf($temp){
	$record="<!--record-->";
	$field="<!--field--->";
	$r=explode($record,$temp);
	$count=count($r);
	for($i=0;$i<$count-1;$i++)
	{
		$r1=explode($field,$r[$i]);
		$str.=",".$r1[1];
	}
	return $str;
}

//组合复选框数据
function ReturnCheckboxAddF($r,$tbname,$f){
	global $public_r;
	$val=$r;
	if(is_array($r)&&strstr($public_r['checkboxf'],','.$tbname.'.'.$f.','))
	{
		$val='';
		$count=count($r);
		for($i=0;$i<$count;$i++)
		{
			$val.=$r[$i].'|';
		}
		if($val)
		{
			$val='|'.$val;
		}
	}
	return $val;
}

//返回自定义字段
function ReturnAddF($add,$modid,$userid,$username,$do=0,$rdata=0,$ch=0){
	global $empire,$public_r,$dbtbpre;
	$record="<!--record-->";
	$field="<!--field--->";
	if($do==0||$do==1||$do==9)
	{
		$addselectf=',mustqenterf,canaddf,caneditf';
		//导入gd处理文件
		if($add['mark']||$add['getfirsttitlespic']||$add['mcreatespic'])
		{
			@include(ECMS_PATH."e/class/gd.php");
		}
	}
	$mr=$empire->fetch1("select tempvar,enter,tbname,listtempvar,dohtmlf,tobrf".$addselectf." from {$dbtbpre}enewsmod where mid='$modid'");
	$r=explode($record,$mr[enter]);
	$count=count($r);
	//增加
	if(empty($do))
	{
		//数据库操作
		for($i=0;$i<$count-1;$i++)
		{
			$r1=explode($field,$r[$i]);
			$f=$r1[1];
			if($f=='special.field'||!strstr($mr['canaddf'],','.$f.','))
			{
				continue;
			}
			$ret_r['fields'].=",".$f;
			$add[$f]=ReturnCheckboxAddF($add[$f],$mr[tbname],$f);//复选框
			$value=RepPhpAspJspcodeText($add[$f]);
			/*
			//新闻内容
			if($f!="newstext"&&!strstr($public_r['tobrf'],",".$mr[tbname].".".$f.","))
			{
				$value=str_replace("<br>","",$value);
	            $value=str_replace("<br />","",$value);
			}
			*/
			//图片集
			if($f=="morepic")
			{
				$value=ReturnMorepicpath($add['msmallpic'],$add['mbigpic'],$add['mpicname'],$add['mdelpicid'],$add['mpicid'],$add,$add['mpicurl_qz'],0);
			}
			//下载地址
			if($f=="downpath")
			{
				$value=ReturnDownpath($add['downname'],$add['downpath'],$add['delpathid'],$add['pathid'],$add['downuser'],$add['fen'],$add['thedownqz'],$add,$add['foruser'],$add['downurl_qz'],0);
			}
			//在线地址
			if($f=="onlinepath")
			{
				$value=ReturnDownpath($add['odownname'],$add['odownpath'],$add['odelpathid'],$add['opathid'],$add['odownuser'],$add['ofen'],$add['othedownqz'],$add,$add['oforuser'],$add['onlineurl_qz'],0);
			}
			//简介
			if($f=="smalltext"&&!trim($value))
			{
				$value=SubSmalltextVal($add[newstext],$public_r[smalltextlen]);//截取新闻内容
			}
			//检测必填字段
			if($ch==1&&empty($add['titleurl']))
			{
				ChMustAddF($f,$value,$mr['mustqenterf']);
				ChIsOnlyAddF(0,$mr[tbname],$f,$value);//唯一值
			}
			//内容
			if($f=="newstext")
			{
				//远程保存
				$value=addslashes(CopyImg(stripSlashes($value),$add[copyimg],$add[copyflash],$add[classid],$add[qz_url],$username,$add['id'],$add['filepass'],$add['mark']));
				//自动分页
				if($add[autopage]&&!strstr($value,"[!--empirenews.page--]"))
				{
					if(empty($add[autosize]))
					{$add[autosize]=5000;}
					$value=AutoDoPage($value,$add[autosize]);
				}
				//存放文本
				if(strstr($public_r['savetxtf'],",".$mr[tbname].".".$f.","))
				{
					//建立目录
					$thetxtfile=GetFileMd5();
					$truevalue=MkDirTxtFile(date("Y/md"),$thetxtfile);
					//写放文件
					EditTxtFieldText($truevalue,$value);
					$value=$truevalue;
				}
			}
			//ip
			if($f=='infoip')
			{
				$value=egetip();
			}
			$ret_r['values'].=",'".addslashes($value)."'";
		}
		//模板字段
		if($rdata==1)//内容
		{
			$ret_r['tempvar']=doReturnAddTempf($mr['tempvar']);
		}
		elseif($rdata==2)//列表
		{
			$ret_r['listtempvar']=doReturnAddTempf($mr['listtempvar']);
		}
		else//全部
		{
			$ret_r['tempvar']=doReturnAddTempf($mr['tempvar']);
			$ret_r['listtempvar']=doReturnAddTempf($mr['listtempvar']);
		}
	}
	//修改
	elseif($do==1)
	{
		//数据库操作
		for($i=0;$i<$count-1;$i++)
		{
			$r1=explode($field,$r[$i]);
			$f=$r1[1];
			if($f=="special.field"||!strstr($mr['caneditf'],','.$f.','))
			{
				continue;
			}
			$ret_r['fields'].=",".$f;
			$add[$f]=ReturnCheckboxAddF($add[$f],$mr[tbname],$f);//复选框
			$value=RepPhpAspJspcodeText($add[$f]);
			/*
			//新闻内容
			if($f!="newstext")
			{
				$value=str_replace("<br>","",$value);
	            $value=str_replace("<br />","",$value);
			}
			*/
			//图片集
			if($f=="morepic")
			{
				$value=ReturnMorepicpath($add['msmallpic'],$add['mbigpic'],$add['mpicname'],$add['mdelpicid'],$add['mpicid'],$add,$add['mpicurl_qz'],1);
			}
			//下载地址
			if($f=="downpath")
			{
				$value=ReturnDownpath($add['downname'],$add['downpath'],$add['delpathid'],$add['pathid'],$add['downuser'],$add['fen'],$add['thedownqz'],$add,$add['foruser'],$add['downurl_qz'],1);
			}
			//在线地址
			if($f=="onlinepath")
			{
				$value=ReturnDownpath($add['odownname'],$add['odownpath'],$add['odelpathid'],$add['opathid'],$add['odownuser'],$add['ofen'],$add['othedownqz'],$add,$add['oforuser'],$add['onlineurl_qz'],1);
			}
			//简介
			if($f=="smalltext"&&!trim($value))
			{
				$value=SubSmalltextVal($add[newstext],$public_r[smalltextlen]);//截取新闻内容
			}
			//检测必填字段
			if($ch==1&&empty($add['titleurl']))
			{
				ChMustAddF($f,$value,$mr['mustqenterf']);
				ChIsOnlyAddF($add[id],$mr[tbname],$f,$value);//唯一值
			}
			//数据同步
			SameDataAddF($add[id],$add[classid],$mr[tbname],$f,$value);
			//内容
			if($f=="newstext")
			{
				//远程保存
				$value=addslashes(CopyImg(stripSlashes($value),$add[copyimg],$add[copyflash],$add[classid],$add[qz_url],$username,$add['id'],$add['filepass'],$add['mark']));
				//自动分页
				if($add[autopage]&&!strstr($value,"[!--empirenews.page--]"))
				{
					if(empty($add[autosize]))
					{$add[autosize]=5000;}
					$value=AutoDoPage($value,$add[autosize]);
				}
				//存放文本
				if(strstr($public_r['savetxtf'],",".$mr[tbname].".".$f.","))
				{
					//建立目录
					$newstexttxt_r=explode("/",$add[newstext_url]);
					$thetxtfile=$newstexttxt_r[2];
					$truevalue=MkDirTxtFile($newstexttxt_r[0]."/".$newstexttxt_r[1],$thetxtfile);
					//写放文件
					EditTxtFieldText($truevalue,$value);
					$value=$truevalue;
				}
			}
			$ret_r['values'].=",".$f."='".addslashes($value)."'";
		}
		//模板字段
		if($rdata==1)//内容
		{
			$ret_r['tempvar']=doReturnAddTempf($mr['tempvar']);
		}
		elseif($rdata==2)//列表
		{
			$ret_r['listtempvar']=doReturnAddTempf($mr['listtempvar']);
		}
		else//全部
		{
			$ret_r['tempvar']=doReturnAddTempf($mr['tempvar']);
			$ret_r['listtempvar']=doReturnAddTempf($mr['listtempvar']);
		}
	}
	//复制
	elseif($do==9)
	{
		//数据库操作
		for($i=0;$i<$count-1;$i++)
		{
			$r1=explode($field,$r[$i]);
			$f=$r1[1];
			if($f=="special.field")
			{continue;}
			$ret_r['fields'].=",".$f;
			$value=RepPhpAspJspcodeText($add[$f]);
			//检测必填字段
			if($ch==1&&empty($add['titleurl']))
			{
				ChMustAddF($f,$value,$mr['mustqenterf']);
				ChIsOnlyAddF(0,$mr[tbname],$f,$value);//唯一值
			}
			//内容
			if($f=="newstext")
			{
				//远程保存
				$value=addslashes(CopyImg(stripSlashes($value),$add[copyimg],$add[copyflash],$add[classid],$add[qz_url],$username,$add['id'],$add['filepass'],$add['mark']));
				//自动分页
				if($add[autopage]&&!strstr($value,"[!--empirenews.page--]"))
				{
					if(empty($add[autosize]))
					{$add[autosize]=5000;}
					$value=AutoDoPage($value,$add[autosize]);
				}
				//存放文本
				if(strstr($public_r['savetxtf'],",".$mr[tbname].".".$f.","))
				{
					//建立目录
					$thetxtfile=GetFileMd5();
					$truevalue=MkDirTxtFile(date("Y/md"),$thetxtfile);
					//写放文件
					EditTxtFieldText($truevalue,$value);
					$value=$truevalue;
				}
			}
			$ret_r['values'].=",'".addslashes(stripSlashes($value))."'";
		}
		//模板字段
		if($rdata==1)//内容
		{
			$ret_r['tempvar']=doReturnAddTempf($mr['tempvar']);
		}
		elseif($rdata==2)//列表
		{
			$ret_r['listtempvar']=doReturnAddTempf($mr['listtempvar']);
		}
		else//全部
		{
			$ret_r['tempvar']=doReturnAddTempf($mr['tempvar']);
			$ret_r['listtempvar']=doReturnAddTempf($mr['listtempvar']);
		}
	}
	//模板
	else
	{
		//模板字段
		if($rdata==1)//内容
		{
			$ret_r['tempvar']=doReturnAddTempf($mr['tempvar']);
		}
		elseif($rdata==2)//列表
		{
			$ret_r['listtempvar']=doReturnAddTempf($mr['listtempvar']);
		}
		else//全部
		{
			$ret_r['tempvar']=doReturnAddTempf($mr['tempvar']);
			$ret_r['listtempvar']=doReturnAddTempf($mr['listtempvar']);
		}
	}
	$ret_r['dohtmlf']=$mr['dohtmlf'];
	$ret_r['tobrf']=$mr['tobrf'];
	return $ret_r;
}

//返回采集字段
function ReturnAddCj($add,$cj,$do=0){
	global $empire;
	$record="<!--record-->";
	$field="<!--field--->";
	$record_r=explode($record,$cj);
	for($i=0;$i<count($record_r)-1;$i++)
	{
		$field_r=explode($field,$record_r[$i]);
		//增加
		if(empty($do))
		{
			$f1="zz_".$field_r[1];
			$f2="z_".$field_r[1];
			$f3="qz_".$field_r[1];
			$f4="save_".$field_r[1];
			$ret_r[0].=",".$f1.",".$f2.",".$f3.",".$f4;
			$ret_r[1].=",'".addslashes($add[$f1])."','".addslashes($add[$f2])."','".addslashes($add[$f3])."','".$add[$f4]."'";
	    }
		//修改
		else
		{
			$f1="zz_".$field_r[1];
			$f2="z_".$field_r[1];
			$f3="qz_".$field_r[1];
			$f4="save_".$field_r[1];
			$ret_r[0].=",".$f1."='".addslashes($add[$f1])."',".$f2."='".addslashes($add[$f2])."',".$f3."='".addslashes($add[$f3])."',".$f4."='".$add[$f4]."'";
	    }
    }
	return $ret_r;
}

//模板变量替换(自定义字段)
function RepTempAddF($field,$r,$temptext){
	global $empire;
	$f=explode(",",$field);
	for($i=1;$i<count($f);$i++)
	{
		$var="[!--".$f[$i]."--]";
		$value=$r[$f[$i]];
		$value=str_replace("<br>","",$value);
		$value=str_replace("<br />","",$value);
		$temptext=str_replace($var,nl2br($value),$temptext);
    }
	return $temptext;
}

//替换全局模板变量
function ReplaceTempvar($temp){
	global $empire;
	if(empty($temp))
	{return $temp;}
	$sql=$empire->query("select myvar,varvalue from ".GetTemptb("enewstempvar")." where isclose=0 order by myorder desc,varid");
	while($r=$empire->fetch($sql))
	{
		$myvar="[!--temp.".$r[myvar]."--]";
		$temp=str_replace($myvar,$r[varvalue],$temp);;
    }
	return $temp;
}

//正则替换信息
function DoRepNewstextZz($oldword,$newword,$text){
	$zztext=RepInfoZZ($oldword,"empire-cms-wm.chief-phome",0);
	$text=preg_replace($zztext,$newword,$text);
	return $text;
}

//批量替换字段值
function DoRepNewstext($start,$oldword,$newword,$field,$classid,$tid,$tbname,$over,$dozz,$dotxt,$userid,$username){
	global $empire,$public_r,$class_r,$fun_r,$dbtbpre;
	$tbname=RepPostVar($tbname);
	$count=count($field);
	if(!$count||empty($oldword)||empty($tbname)||!$tid)
	{
		printerror("FailCX","history.go(-1)");
	}
	CheckLevel($userid,$username,$classid,"repnewstext");//验证权限
	//变量替换
	$postoldword=ClearAddsData($oldword);
	$postnewword=ClearAddsData($newword);
	//替换条件
	if($classid)//按栏目替换
	{
		if(empty($class_r[$classid][islast]))//中级栏目
		{
			$where=ReturnClass($class_r[$classid][sonclass]);
		}
		else//终极栏目
		{
			$where="classid='$classid'";
		}
		$add1=" and (".$where.")";
		$add2=" where (".$where.")";
    }
	//存文本替换
	if($dotxt==1)
	{
		$f=RepPostVar($field[0]);
		if(!strstr($public_r['savetxtf'],",".$tbname.".".$f.","))
		{
			printerror("FailCX","history.go(-1)");
		}
		$repoldword=addslashes($postoldword);
		$repnewword=addslashes($postnewword);
		//字段
		$selectf=",".$f;
		$fieldform="<input type='hidden' name='field[]' value='".$f."'>";
		if(empty($public_r[dorepnum]))
		{
			$public_r[dorepnum]=600;
		}
		$start=(int)$start;
		$b=0;
		$sql=$empire->query("select id".$selectf." from {$dbtbpre}ecms_".$tbname." where id>$start".$add1." and titleurl='' order by id limit ".$public_r[dorepnum]);
		while($r=$empire->fetch($sql))
		{
			$b=1;
			$newstart=$r[id];
			$value=GetTxtFieldText($r[$f]);
			if(empty($value))
			{
				continue;
			}
			if($dozz==1)//正则
			{
				$newvalue=DoRepNewstextZz($repoldword,$repnewword,$value);//正则替换
			}
			else//普通
			{
				if(!stristr($value,$repoldword))
				{
					continue;
				}
				$newvalue=str_replace($repoldword,$repnewword,$value);
			}
			EditTxtFieldText($r[$f],$newvalue);
		}
		//替换完毕
		if(empty($b))
		{
			insert_dolog("tbname=".$tbname."<br>oldword=".$oldword."<br>newword=".$newword);//操作日志
			printerror("DoRepNewstextSuccess","db/RepNewstext.php?tid=$tid");
		}
		EchoRepFieldForm($tid,$tbname,$over,$dozz,$dotxt,$newstart,$fieldform,$classid,$postoldword,$postnewword);
	}
	//正则替换
	elseif($dozz==1)
	{
		//字段
		for($i=0;$i<$count;$i++)
		{
			$f=RepPostVar($field[$i]);
			$selectf.=",".$f;
			$fieldform.="<input type='hidden' name='field[]' value='".$f."'>";
		}
		if(empty($public_r[dorepnum]))
		{
			$public_r[dorepnum]=600;
		}
		$start=(int)$start;
		$b=0;
		$sql=$empire->query("select id".$selectf." from {$dbtbpre}ecms_".$tbname." where id>$start".$add1." and titleurl='' order by id limit ".$public_r[dorepnum]);
		while($r=$empire->fetch($sql))
		{
			$b=1;
			$newstart=$r[id];
			//字段
			$setf="";
			$dh="";
			for($i=0;$i<$count;$i++)
			{
				$f=RepPostVar($field[$i]);
				$newvalue=DoRepNewstextZz($oldword,$newword,stripSlashes($r[$f]));//正则替换
				$setf.=$dh.$f."='".addslashes($newvalue)."'";
				$dh=",";
			}
			$usql=$empire->query("update {$dbtbpre}ecms_".$tbname." set ".$setf." where id='$r[id]'");
		}
		//替换完毕
		if(empty($b))
		{
			insert_dolog("tbname=".$tbname."<br>oldword=".$oldword."<br>newword=".$newword);//操作日志
			printerror("DoRepNewstextSuccess","db/RepNewstext.php?tid=$tid");
		}
		EchoRepFieldForm($tid,$tbname,$over,$dozz,$dotxt,$newstart,$fieldform,$classid,$postoldword,$postnewword);
	}
	//普通替换
	else
	{
		$repoldword=addslashes($oldword);
		$repnewword=addslashes($newword);
		if($over==1)//完全替换
		{
			if(empty($add2))
			{
				$and=" where ";
			}
			else
			{
				$and=" and ";
			}
		}
		$dh="";
		for($i=0;$i<$count;$i++)
		{
			$f=RepPostVar($field[$i]);
			if($over==1)//完全替换
			{
				$add2.=$and.$f."='".$repoldword."'";
				$and=" and ";
			}
			$setf.=$dh.$f."=REPLACE(".$f.",'$repoldword','$repnewword')";
			$dh=",";
		}
		$sql=$empire->query("update {$dbtbpre}ecms_".$tbname." set ".$setf.$add2);
		//替换完毕
		if($sql)
		{
			insert_dolog("tbname=".$tbname."<br>oldword=".$oldword."<br>newword=".$newword);//操作日志
			printerror("DoRepNewstextSuccess","db/RepNewstext.php?tid=$tid");
		}
		else
		{
			printerror("DbError","");
		}
	}
}

//输出批量替换字段表单
function EchoRepFieldForm($tid,$tbname,$over,$dozz,$dotxt,$newstart,$fieldform,$classid,$oldword,$newword){
	global $fun_r;
	?>
	<?=$fun_r['RepOneNewstextSuccess']?>(ID:<font color=red><b><?=$newstart?></b></font>)
	<form name="RepFieldForm" method="post" action="enews.php">
		<input type=hidden name="enews" value="DoRepNewstext">
		<input type=hidden name="tid" value="<?=$tid?>">
		<input type=hidden name="tbname" value="<?=$tbname?>">
		<input type=hidden name="over" value="<?=$over?>">
		<input type=hidden name="dozz" value="<?=$dozz?>">
		<input type=hidden name="dotxt" value="<?=$dotxt?>">
		<input type=hidden name="start" value="<?=$newstart?>">
		<?=$fieldform?>
		<input type=hidden name="classid" value="<?=$classid?>">
		<input type=hidden name="oldword" value="<?=htmlspecialchars($oldword)?>">
		<input type=hidden name="newword" value="<?=htmlspecialchars($newword)?>">
	</form>
	<script>
	document.RepFieldForm.submit();
	</script>
	<?
	exit();
}

//自动分页
function AutoDoPage($mybody,$spsize){
  $sptag="[!--empirenews.page--]";
  if(strlen($mybody)<$spsize) return $mybody;
  $bds = explode('<',$mybody);
  $npageBody = "";
  $istable = 0;
  $mybody = "";
  foreach($bds as $i=>$k)
  {
  	 if($i==0){ $npageBody .= $bds[$i]; continue;}
  	 $bds[$i] = "<".$bds[$i];
  	 if(strlen($bds[$i])>6){
  		  $tname = substr($bds[$i],1,5);
  		  if(strtolower($tname)=='table') $istable++;
  		  else if(strtolower($tname)=='/tabl') $istable--;
  		  if($istable>0){ $npageBody .= $bds[$i]; continue; }
  		  else $npageBody .= $bds[$i];
  	 }else{
  		  $npageBody .= $bds[$i];
  	 }
  	 if(strlen($npageBody)>$spsize){
  		  $mybody .= $npageBody.$sptag;
  		  $npageBody = "";
     }
  }
  if($npageBody!="") $mybody .= $npageBody;
  return $mybody;
}
//自动分页结束

//返回文件名
function ReturnPathFile($filename){
	$fr=explode("/",$filename);
	$count=count($fr)-1;
	return $fr[$count];
}

//批量导入栏目模板
function LoadTempInClass($path,$start,$userid,$username){
	global $empire,$public_r,$dbtbpre;
	//验证权限
	CheckLevel($userid,$username,$classid,"template");
	$start=(int)$start;
	if(empty($public_r[loadtempnum]))
	{$public_r[loadtempnum]=50;}
	$b=0;
	$sql=$empire->query("select classid,classtempid from {$dbtbpre}enewsclass where islast=0 and islist=0 and classid>$start order by classid limit ".$public_r[loadtempnum]);
	while($r=$empire->fetch($sql))
	{
		$b=1;
		$newstart=$r[classid];
		$file="../data/LoadTemp/".$r[classid].".htm";
		if(file_exists($file))
		{
			$data=addslashes(ReadFiletext($file));
			$data=RepPhpAspJspcode($data);
			$usql=$empire->query("update {$dbtbpre}enewsclasstemp set temptext='".$data."' where tempid='$r[classtempid]'");
			NewsBq($r[classid],$data,0,0);
	    }
    }
	if(empty($b))
	{
		//操作日志
	    insert_dolog("");
		printerror("LoadClassTempSuccess","template/LoadTemp.php");
	}
	echo $fun_r['LoadOneTempSuccess']."(ID:<font color=red><b>".$newstart."</b></font>)<script>self.location.href='enews.php?enews=LoadTempInClass&start=$newstart';</script>";
	exit();
}

//批量更换栏目列表模板
function ChangeClassListtemp($classid,$listtempid,$userid,$username){
	global $empire,$class_r,$dbtbpre;
	if(empty($listtempid))
	{printerror("EmptChangeListtempid","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"template");
	$listtempid=(int)$listtempid;
	if(empty($classid))
	{$where="classid<>0";}
	else
	{
		//中级栏目
		if(empty($class_r[$classid][islast]))
		{
			$where=ReturnClass($class_r[$classid][sonclass]);
		}
		//终极栏目
		else
		{
			$where="classid='$classid'";
		}
	}
	$sql=$empire->query("update {$dbtbpre}enewsclass set listtempid=$listtempid where ".$where);
	GetClass();
	if($sql)
	{
		//操作日志
		insert_dolog("classid=$classid&listtempid=$listtempid");
		printerror("ChangeClassListtempSuccess","history.go(-1)");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//定时刷新任务
function DoTimeRepage($time){
	global $empire,$dbtbpre;
	if(empty($time))
	{$time=480;}
	echo"<meta http-equiv=\"refresh\" content=\"".$time.";url=DoTimeRepage.php\">";
	$todaytime=time();
	$sql=$empire->query("select doing,classid,doid from {$dbtbpre}enewsdo where isopen=1 and lasttime+dotime*60<$todaytime");
	while($r=$empire->fetch($sql))
	{
		//刷新栏目
		if($r[doing]==1)
		{
			if($r[classid])
			{
				ReListHtml($r[classid],1);
			}
	    }
		//刷新首页
		else
		{
			//取得模板
			$indextemp=GetIndextemp();
			NewsBq($classid,$indextemp,1,0);
	    }
		$usql=$empire->query("update {$dbtbpre}enewsdo set lasttime=$todaytime where doid='$r[doid]'");
    }
}

//签发文章
function DoCheckUser($add,$userid,$username){
	global $empire,$class_r,$dbtbpre,$logininid,$loginin;
	$add[id]=(int)$add[id];
	$add[classid]=(int)$add[classid];
	$checktime=date("Y-m-d H:i:s");
	if(empty($add[id])||!$add[classid])
	{
		printerror("ErrorUrl","history.go(-1)");
    }
	$r=$empire->fetch1("select classid,id,checkuser,docheckuser,viewcheckuser,returncheck,notdocheckuser,userchecktime from {$dbtbpre}enewsqf where id='$add[id]' and classid='$add[classid]' limit 1");
	if(empty($r[docheckuser]))
	{
		$r[docheckuser]=",";
	}
	if(empty($r[viewcheckuser]))
	{
		$r[viewcheckuser]=",";
	}
	if(empty($r[notdocheckuser]))
	{
		$r[notdocheckuser]=",";
	}
	$var=",".$username.",";
	if(!strstr($r[checkuser],$var))
	{
		printerror("NotDoCheckUserLevel","history.go(-1)");
	}
	if(strstr($r[docheckuser],$var))
	{
		printerror("HaveDoCheckUser","history.go(-1)");
	}
	if(strstr($r[notdocheckuser],$var))
	{
		printerror("HaveNotDoCheckUser","history.go(-1)");
	}
	//通过
	if(empty($add['doing']))
	{
		$docheckuser=$r[docheckuser].$username.",";
		$userchecktime=unserialize($r[userchecktime]);
		$userchecktime[$username]=$checktime;
		if(!strstr($r[viewcheckuser],$var))
		{
			$viewcheckuser=$r[viewcheckuser].$username.",";
		}
		else
		{
			$viewcheckuser=$r[viewcheckuser];
		}
		if(strlen($docheckuser)==strlen($r[checkuser]))//通过此处判断文章状态是否已经完全签发
		{
			$a=",checked=1";
			$usql=$empire->query("update {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." set checked=1 where id='$add[id]'");
		}
		$sql=$empire->query("update {$dbtbpre}enewsqf set userchecktime='".serialize($userchecktime)."',docheckuser='".addslashes($docheckuser)."',viewcheckuser='".addslashes($viewcheckuser)."'".$a." where id='$add[id]' and classid='$add[classid]' limit 1");
		$mess="DoCheckUserSuccess";
		//if($a) //如果全部签发则自动通过审核并生成内容页面html
		//{ 
    //  $modid=$class_r[$r[classid]][modid];
		//	$fr=ReturnAddF($r,$modid,$userid,$username,2,2,0);
		//	ListHtml($r[classid],$fr,0);
		//	include_once("comdofun.php");
    //  CheckNews_all($add[classid],$add[id],$logininid,$loginin,true);//这里传递true实在审核信息时候保证能够被处理
		//}
	}
	//退回
	else
	{
		if(empty($add[checktext]))
		{
			printerror("EmptyChecktext","history.go(-1)");
		}
		$notdocheckuser=$r[notdocheckuser].$username.",";
		if(!strstr($r[viewcheckuser],$var))
		{
			$viewcheckuser=$r[viewcheckuser].$username.",";
		}
		else
		{
			$viewcheckuser=$r[viewcheckuser];
		}
		$sql=$empire->query("update {$dbtbpre}enewsqf set notdocheckuser='".addslashes($notdocheckuser)."',viewcheckuser='".addslashes($viewcheckuser)."',returncheck=1 where id='$add[id]' and classid='$add[classid]' limit 1");
		//写入评语表
		$userid=(int)$userid;
		$usql=$empire->query("insert into {$dbtbpre}enewschecktext(userid,username,checktext,id,checktime,isold,classid) values($userid,'$username','$add[checktext]',$add[id],'$checktime',0,$add[classid]);");
		$mess="NotDoCheckUserSuccess";
	}
	if($sql)
	{
		//操作日志
	    insert_dolog("classid=$add[classid]&id=$add[id]");
		printerror($mess,"DoNewsQf.php?classid=$add[classid]&id=$add[id]");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//查看签发内容
function ViewQfNews($id,$classid,$userid,$username){
	global $empire,$class_r,$public_r,$dbtbpre;
	$id=(int)$id;
	$classid=(int)$classid;
	if(empty($id)||empty($classid))
	{
		printerror("ErrorUrl","history.go(-1)");
	}
	$r=$empire->fetch1("select id,newspath,classid,groupid,filename,titleurl from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where id='$id'");
	$add=$empire->fetch1("select id,checkuser,viewcheckuser from {$dbtbpre}enewsqf where id='$id' and classid='$classid' limit 1");
	if(!$add[id])
	{
		printerror("NotDoCheckUserLevel","history.go(-1)");
	}
	if(empty($add[viewcheckuser]))
	{
		$add[viewcheckuser]=",";
	}
	$like=",".$username.",";
	if(!strstr($add[checkuser],$like))
	{
		printerror("NotDoCheckUserLevel","history.go(-1)");
	}
	//链接
	$titleurl=sys_ReturnBqTitleLink($r);
	if(!strstr($add[viewcheckuser],$like))
	{
		$viewcheckuser=$add[viewcheckuser].$username.",";
		$sql=$empire->query("update {$dbtbpre}enewsqf set viewcheckuser='".addslashes($viewcheckuser)."' where id='$id' and classid='$classid' limit 1");
	}
	Header("Location:$titleurl");
}

//恢复栏目目录
function ReClassPath($start=0){
	global $empire,$public_r,$dbtbpre;
	$start=(int)$start;
	$sql=$empire->query("select classid,classpath,islast from {$dbtbpre}enewsclass where wburl='' and classid>$start order by classid limit ".$public_r[relistnum]);
	$b=0;
	while($r=$empire->fetch($sql))
	{
		$b=1;
		$newstart=$r[classid];
		$returnpath=FormatClassPath($r[classpath],$r[islast]);
		echo "Create Path:".$returnpath." success!<br>";
    }
	//恢复专题目录
	if(empty($b))
	{
		$zsql=$empire->query("select ztid,ztpath from {$dbtbpre}enewszt order by ztid");
		while($zr=$empire->fetch($zsql))
		{
			CreateZtPath($zr[ztpath]);
		}
	}
	if(empty($b))
	{
		//操作日志
	    insert_dolog("");
		printerror("ReClassPathSuccess","ReHtml/ChangeData.php");
	}
	echo"(ID:<font color=red><b>".$newstart."</b></font>)<script>self.location.href='enews.php?enews=ReClassPath&start=$newstart';</script>";
	exit();
}

//建立栏目目录
function FormatClassPath($classpath,$islast){
	$r=explode("/",$classpath);
	$returnpath="";
	for($i=0;$i<count($r);$i++)
	{
		if($i>0)
		{
			$returnpath.="/".$r[$i];
		}
		else
		{
			$returnpath.=$r[$i];
		}
		CreateClassPath($returnpath);
	}
	return $returnpath;
}

//返回栏目链接(无缓存)
function sys_ReturnBqClassUrl($r){
	global $public_r;
	//外部栏目
	if($r[wburl])
	{
		$classurl=$r[wburl];
	}
	//动态列表
	elseif($r['listdt'])
	{
		$classurl=$public_r['newsurl']."e/action/ListInfo/?classid=$r[classid]";
	}
	elseif($r['classurl'])
	{
		$classurl=$r['classurl'];
	}
	else
	{
		$classurl=$public_r['newsurl'].$r['classpath']."/";
	}
	return $classurl;
}

//返回专题链接(无缓存)
function sys_ReturnBqZtUrl($r){
	global $public_r;
	if($r['zturl'])
	{
		$zturl=$r['zturl'];
    }
	else
	{
		$zturl=$public_r['newsurl'].$r['ztpath']."/";
    }
	return $zturl;
}

//更新栏目关系
function ChangeSonclass($start,$userid,$username){
	global $empire,$public_r,$fun_r,$dbtbpre;
	//验证权限
	CheckLevel($userid,$username,$classid,"changedata");
	$start=(int)$start;
	$b=0;
	$sql=$empire->query("select classid from {$dbtbpre}enewsclass where islast=0 and classid>".$start." order by classid limit ".$public_r[relistnum]);
	while($r=$empire->fetch($sql))
	{
		$b=1;
		$newstart=$r[classid];
		//子栏目
		$sonclass="|";
		$ssql=$empire->query("select classid from {$dbtbpre}enewsclass where islast=1 and featherclass like '%|".$r[classid]."|%' order by classid");
		while($sr=$empire->fetch($ssql))
		{
			$sonclass.=$sr[classid]."|";
	    }
		$usql=$empire->query("update {$dbtbpre}enewsclass set sonclass='$sonclass' where classid='$r[classid]'");
    }
	//完毕
	if(empty($b))
	{
		GetClass();
		printerror("ChangeSonclassSuccess","ReHtml/ChangeData.php");
	}
	echo $fun_r['OneChangeSonclassSuccess']."(ID:<font color=red><b>".$newstart."</b></font>)<script>self.location.href='enews.php?enews=ChangeSonclass&start=$newstart';</script>";
	exit();
}

//组合两数组
function TogTwoArray($r,$ra){
	if(!is_array($ra))
	{
		return $r;
	}
	foreach($r as $key => $value)
	{
		$returnr[$key]=$value;
	}
	foreach($ra as $keya => $valuea)
	{
		$returnr[$keya]=$valuea;
	}
	return $returnr;
}


//返回随机字符
function ReturnNotcj($string){
	global $notcj_r,$notcjnum;
	if(empty($notcjnum))
	{
		$rep="";
    }
	else
	{
		$i=rand(1,$notcjnum);
		$rep=$notcj_r[$i];
    }
	$cjword="<!--ecms.*-->";
	$string=str_replace($cjword,$rep,$string);
	return $string;
}

//替换自定义页面标签
function RepUserpageVar($pagetext,$title,$pagetitle,$pagekeywords,$pagedescription){
	$pagetext=str_replace("[!--pagetitle--]",$pagetitle,$pagetext);
	$pagetext=str_replace("[!--pagekeywords--]",$pagekeywords,$pagetext);
	$pagetext=str_replace("[!--pagedescription--]",$pagedescription,$pagetext);
	return $pagetext;
}

//生成自定义页面
function ReUserpage($id,$pagetext,$path,$title="",$pagetitle,$pagekeywords,$pagedescription){
	global $public_r;
	if(empty($path))
	{
		return "";
	}
	if(empty($pagetitle))
	{
		$pagetitle=$title;
	}
	$pagetext=NewsBq("page".$id,$pagetext,2,0);
	$pagetext=RepUserpageVar($pagetext,$title,$pagetitle,$pagekeywords,$pagedescription);
	$pagetext=str_replace("[!--news.url--]",$public_r['newsurl'],$pagetext);
	WriteFiletext($path,$pagetext);
}

//批量刷新自定义页面
function ReUserpageAll($start=0,$from,$userid,$username){
	global $empire,$public_r,$fun_r,$dbtbpre;
	$start=(int)$start;
	$b=0;
	$sql=$empire->query("select id,path,pagetext,title,pagetitle,pagekeywords,pagedescription from {$dbtbpre}enewspage where id>$start order by id limit ".$public_r['reuserpagenum']);
	while($r=$empire->fetch($sql))
	{
		$b=1;
		$newstart=$r[id];
		ReUserpage($r[id],$r[pagetext],$r[path],$r[title],$r[pagetitle],$r[pagekeywords],$r[pagedescription]);
	}
	//完毕
	if(empty($b))
	{
		//操作日志
	    insert_dolog("");
		printerror("ReUserpageAllSuccess",$from);
	}
	echo $fun_r['OneReUserpageSuccess']."(ID:<font color=red><b>".$newstart."</b></font>)<script>self.location.href='enews.php?enews=ReUserpageAll&start=$newstart&from=$from';</script>";
	exit();
}

//转向处理文件
function GoReListHtmlMore($classid,$gore,$from){
	global $empire,$class_r;
	$count=count($classid);
	if($count==0)
	{
		printerror("EmptyReListHtmlMoreId","history.go(-1)");
    }
	$cid="";
	for($i=0;$i<$count;$i++)
	{
		if($i==0)
		{
			$fh="";
		}
		else
		{
			$fh=",";
		}
		$cid.=$fh.$classid[$i];
	}
	//栏目
	if(empty($gore))
	{
		$phome="ReListHtmlMore";
	}
	//专题
	else
	{
		$phome="ReListZtHtmlMore";
	}
	echo"<script>self.location.href='enews.php?enews=$phome&classid=$cid&from=$from';</script>";
	exit();
}

//刷新多列表
function ReListHtmlMore($start,$classid,$from){
	global $empire,$public_r,$fun_r,$class_r,$dbtbpre;
	$start=(int)$start;
	$classid=RepPostVar($classid);
	if(empty($classid))
	{
		printerror("ErrorUrl",$from);
    }
	$b=0;
	$sql=$empire->query("select classid,classtempid,islast,islist from {$dbtbpre}enewsclass where classid>$start and classid in(".$classid.") order by classid limit ".$public_r[relistnum]);
	while($r=$empire->fetch($sql))
	{
		//返回字段
		$ret_r=ReturnAddF($r,$class_r[$r[classid]][modid],$userid,$username,2,2,0);
		$b=1;
		//大栏目
		if(!$r[islast])
		{
			if($r[islist])
			{ListHtml($r[classid],$ret_r,3);}
			else
			{NewsBq($r[classid],GetClassTemp($r['classtempid']),0,0);}
		}
		//子栏目
		else
		{
			ListHtml($r[classid],$ret_r,0);
		}
		$end_classid=$r[classid];
	}
	if(empty($b))
	{
		//操作日志
		insert_dolog("");
		printerror("ReClassidAllSuccess",$from);
    }
	echo $fun_r[OneReListNewsSuccess]."(ID:<font color=red><b>".$end_classid."</b></font>)<script>self.location.href='enews.php?enews=ReListHtmlMore&start=$end_classid&classid=$classid&from=$from';</script>";
	exit();
}

//刷新多专题列表
function ReListZtHtmlMore($start,$classid,$from){
	global $empire,$public_r,$fun_r,$class_r,$dbtbpre;
	$start=(int)$start;
	$classid=RepPostVar($classid);
	if(empty($classid))
	{
		printerror("ErrorUrl",$from);
    }
	$b=0;
	//刷新专题
	$zsql=$empire->query("select ztid,ztname,ztnum,listtempid,classid from {$dbtbpre}enewszt where ztid>$start and ztid in(".$classid.") order by ztid limit ".$public_r[relistnum]);
    while($z_r=$empire->fetch($zsql))
	{
		$b=1;
        ListHtml($z_r[ztid],$ret_r,1);
		$end_classid=$z_r[ztid];
    }
	if(empty($b))
	{
		//操作日志
		insert_dolog("");
		printerror("ReClassidAllSuccess",$from);
    }
    echo $fun_r[OneReZtListNewsSuccess]."(ZtID:<font color=red><b>".$end_classid."</b></font>)<script>self.location.href='enews.php?enews=ReListZtHtmlMore&start=$end_classid&classid=$classid&from=$from';</script>";
    exit();
}

//删除栏目缓存文件
function DelFcListClass(){
	DelListEnews();
	//操作日志
	insert_dolog("");
	printerror("DelListEnewsSuccess","history.go(-1)");
}

//批量删除信息
function DelInfoData($start,$classid,$from,$retype,$startday,$endday,$startid,$endid,$tbname,$userid,$username){
	global $empire,$public_r,$class_r,$fun_r,$dbtbpre;
	//验证权限
	CheckLevel($userid,$username,$classid,"delinfodata");
	$start=(int)$start;
	$tbname=RepPostVar($tbname);
	if(empty($tbname))
	{
		printerror("ErrorUrl","history.go(-1)");
    }
	//按栏目刷新
	$classid=(int)$classid;
	if($classid)
	{
		if(empty($class_r[$classid][islast]))//大栏目
		{
			$where=ReturnClass($class_r[$classid][sonclass]);
		}
		else//终极栏目
		{
			$where="classid='$classid'";
		}
		$add1=" and (".$where.")";
    }
	//按ID刷新
	if($retype)
	{
		$startid=(int)$startid;
		$endid=(int)$endid;
		if($endid)
		{
			$add1.=" and id>=$startid and id<=$endid";
	    }
    }
	else
	{
		$startday=RepPostVar($startday);
		$endday=RepPostVar($endday);
		if($startday&&$endday)
		{
			$add1.=" and truetime>=".to_time($startday." 00:00:00")." and truetime<=".to_time($endday." 23:59:59");
	    }
    }
	$b=0;
	$sql=$empire->query("select * from {$dbtbpre}ecms_".$tbname." where id>$start".$add1." order by id limit ".$public_r[delnewsnum]);
	while($r=$empire->fetch($sql))
	{
		$b=1;
		$new_start=$r[id];
		//存放文本
		if(strstr($public_r['savetxtf'],",".$class_r[$r[classid]][tbname].".newstext,"))
		{
			$newstextfile=$r[newstext];
			$r[newstext]=GetTxtFieldText($r[newstext]);
			//删除文件
			DelTxtFieldText($newstextfile);
		}
		//删除信息文件
		DelNewsFile($r[filename],$r[newspath],$r[classid],$r[newstext],$r[groupid]);
		$usql=$empire->query("delete from {$dbtbpre}ecms_".$tbname." where id='$r[id]'");
		//删除其它表记录
		$delsql=$empire->query("delete from {$dbtbpre}enewsqf where id='$r[id]' and classid='$r[classid]'");
		$delsql=$empire->query("delete from {$dbtbpre}enewsinfovote where id='$r[id]' and classid='$r[classid]'");
		$delsql=$empire->query("delete from {$dbtbpre}enewsdiggips where id='$r[id]' and classid='$r[classid]'");
		//删除附件
		DelNewsTheFile($r['id'],$r['classid']);
	}
	if(empty($b))
	{
	    //操作日志
	    insert_dolog("");
		printerror("DelNewsAllSuccess","db/DelData.php");
	}
	echo $fun_r[OneDelDataSuccess]."(ID:<font color=red><b>".$new_start."</b></font>)<script>self.location.href='enews.php?enews=DelInfoData&tbname=$tbname&classid=$classid&start=$new_start&from=$from&retype=$retype&startday=$startday&endday=$endday&startid=$startid&endid=$endid';</script>";
	exit();
}


//返回类别管理操作信息
function ReturnDoclassVar($ecms){
	global $dbtbpre;
	//标签模板分类
	if($ecms=="bqtemp")
	{
		$r['tbname']=$dbtbpre."enewsbqtempclass";
		$r['mess']="Bqtemp";
		$r['thelevel']="template";
		$r['returnpage']="template/BqtempClass.php";
	}
	//用户自定义页面分类
	elseif($ecms=="page")
	{
		$r['tbname']=$dbtbpre."enewspageclass";
		$r['mess']="Page";
		$r['thelevel']="userpage";
		$r['returnpage']="template/PageClass.php";
	}
	//公共模板变量分类
	elseif($ecms=="tempvar")
	{
		$r['tbname']=$dbtbpre."enewstempvarclass";
		$r['mess']="Tempvar";
		$r['thelevel']="tempvar";
		$r['returnpage']="template/TempvarClass.php";
	}
	//列表模板分类
	elseif($ecms=="listtemp")
	{
		$r['tbname']=$dbtbpre."enewslisttempclass";
		$r['mess']="Listtemp";
		$r['thelevel']="template";
		$r['returnpage']="template/ListtempClass.php";
	}
	//内容模板分类
	elseif($ecms=="newstemp")
	{
		$r['tbname']=$dbtbpre."enewsnewstempclass";
		$r['mess']="Newstemp";
		$r['thelevel']="template";
		$r['returnpage']="template/NewstempClass.php";
	}
	//搜索模板分类
	elseif($ecms=="searchtemp")
	{
		$r['tbname']=$dbtbpre."enewssearchtempclass";
		$r['mess']="Searchtemp";
		$r['thelevel']="template";
		$r['returnpage']="template/SearchtempClass.php";
	}
	//标签分类
	elseif($ecms=="bq")
	{
		$r['tbname']=$dbtbpre."enewsbqclass";
		$r['mess']="Bq";
		$r['thelevel']="bq";
		$r['returnpage']="template/BqClass.php";
	}
	//JS模板
	elseif($ecms=="jstemp")
	{
		$r['tbname']=$dbtbpre."enewsjstempclass";
		$r['mess']="Jstemp";
		$r['thelevel']="template";
		$r['returnpage']="template/JsTempClass.php";
	}
	//专题
	elseif($ecms=="zt")
	{
		$r['tbname']=$dbtbpre."enewsztclass";
		$r['mess']="Ztclass";
		$r['thelevel']="zt";
		$r['returnpage']="ListZtClass.php";
	}
	//友情链接
	elseif($ecms=="link")
	{
		$r['tbname']=$dbtbpre."enewslinkclass";
		$r['mess']="Linkclass";
		$r['thelevel']="link";
		$r['returnpage']="tool/LinkClass.php";
	}
	//单页模板
	elseif($ecms=="classtemp")
	{
		$r['tbname']=$dbtbpre."enewsclasstempclass";
		$r['mess']="Classtemp";
		$r['thelevel']="template";
		$r['returnpage']="template/ClassTempClass.php";
	}
	else
	{
		printerror("ErrorUrl","history.go(-1)");
	}
	return $r;
}

//增加分类
function AddThisClass($add,$userid,$username){
	global $empire,$dbtbpre;
	//取得返回信息
	$thisr=ReturnDoclassVar($add['doing']);
	if(!$add['classname'])
	{
		printerror("Empty".$thisr['mess']."Classname","history.go(-1)");
    }
	//验证权限
    CheckLevel($userid,$username,$classid,$thisr['thelevel']);
	$sql=$empire->query("insert into ".$thisr['tbname']."(classname) values('$add[classname]');");
	if($sql)
	{
		$lastid=$empire->lastid();
		//操作日志
	    insert_dolog("classid=".$lastid."<br>classname=".$add[classname]);
		printerror("Add".$thisr['mess']."ClassSuccess",$thisr['returnpage']);
	}
	else
	{
		printerror("DbError","history.go(-1)");
	}
}

//修改分类
function EditThisClass($add,$userid,$username){
	global $empire,$dbtbpre;
	//取得返回信息
	$thisr=ReturnDoclassVar($add['doing']);
	$classid=(int)$add['classid'];
	if(!$add['classname']||!$classid)
	{
		printerror("Empty".$thisr['mess']."Classname","history.go(-1)");
    }
	//验证权限
    CheckLevel($userid,$username,$classid,$thisr['thelevel']);
	$sql=$empire->query("update ".$thisr['tbname']." set classname='$add[classname]' where classid='$classid'");
	if($sql)
	{
		//操作日志
		insert_dolog("classid=".$classid."<br>classname=".$add[classname]);
		printerror("Edit".$thisr['mess']."ClassSuccess",$thisr['returnpage']);
	}
	else
	{
		printerror("DbError","history.go(-1)");
	}
}

//删除分类
function DelThisClass($classid,$doing,$userid,$username){
	global $empire,$dbtbpre;
	//取得返回信息
	$thisr=ReturnDoclassVar($doing);
	$classid=(int)$classid;
	if(!$classid)
	{
		printerror("NotChange".$thisr['mess']."Classid","history.go(-1)");
    }
	//验证权限
    CheckLevel($userid,$username,$classid,$thisr['thelevel']);
	$r=$empire->fetch1("select classname from ".$thisr['tbname']." where classid=$classid");
	$sql=$empire->query("delete from ".$thisr['tbname']." where classid=$classid");
	if($sql)
	{
		//操作日志
		insert_dolog("classid=".$classid."<br>classname=".$r[classname]);
		printerror("Del".$thisr['mess']."ClassSuccess",$thisr['returnpage']);
	}
	else
	{
		printerror("DbError","history.go(-1)");
	}
}

//取得js模板
function GetTheJstemp($tempid){
	global $empire;
	$r=$empire->fetch1("select temptext,showdate from ".GetTemptb("enewsjstemp")." where tempid='$tempid'");
	return $r;
}

//--------------读取文本字段内容
function GetTxtFieldText($pagetexturl){
	global $do_txtpath,$addgethtmlpath;
	$file=$addgethtmlpath.$do_txtpath.$pagetexturl.".php";
	$text=ReadFiletext($file);
	$text=substr($text,12);//去除exit
	return $text;
}

//--------------取得文本地址
function GetTxtFieldTextUrl($pagetexturl){
	global $do_txtpath,$addgethtmlpath;
	$file=$addgethtmlpath.$do_txtpath.$pagetexturl.".php";
	return $file;
}

//--------------修改文本字段内容
function EditTxtFieldText($pagetexturl,$pagetext){
	global $do_txtpath,$addgethtmlpath;
	$pagetext="<? exit();?>".$pagetext;
	$file=$addgethtmlpath.$do_txtpath.$pagetexturl.".php";
	WriteFiletext_n($file,$pagetext);
}

//--------------删除文本字段内容
function DelTxtFieldText($pagetexturl){
	global $do_txtpath,$addgethtmlpath;
	$file=$addgethtmlpath.$do_txtpath.$pagetexturl.".php";
	DelFiletext($file);
}

//-------------------------取得随机数
function GetFileMd5(){
	$p=md5(uniqid(microtime()));
	return $p;
}

//-------------------------建立存放目录
function MkDirTxtFile($date,$file){
	global $do_txtpath,$addgethtmlpath;
	$r=explode("/",$date);
	$path=$addgethtmlpath.$do_txtpath.$r[0];
	DoMkdir($path);
	$path=$addgethtmlpath.$do_txtpath.$date;
	DoMkdir($path);
	$returnpath=$date."/".$file;
	return $returnpath;
}

//导出标签
function LoadOutBq($add,$userid,$username){
	global $empire,$dbtbpre;
	$bqid=(int)$add['bqid'];
	if(!$bqid||!$add['funvalue'])
	{
		printerror("EmptyLoadBqid","history.go(-1)");
	}
	//验证权限
    CheckLevel($userid,$username,$classid,"bq");
	$r=$empire->fetch1("select bqid,bqname,bqsay,funname,bq,bqgs from {$dbtbpre}enewsbq where bqid=$bqid");
	if(!$r[bqid])
	{
		printerror("NotThisBqid","history.go(-1)");
	}
	$add['funvalue']=ClearAddsData($add['funvalue']);
	$field="<!--#empirecms.bq-phome.net#--!>";
	$str=$r['bqname'].$field.stripSlashes($r['bqsay']).$field.$r['funname'].$field.$r['bq'].$field.stripSlashes($r['bqgs']).$field.$add['funvalue'];
	$filename=$r['bq'].time().".bq";
	$filepath="template/data/".$filename;
	WriteFiletext_n($filepath,$str);
	DownLoadFile($filename,$filepath,1);
	//操作日志
	insert_dolog("bqid=".$bqid."<br>bqname=".$r[bqname]);
	exit();
}

//下载
function DownLoadFile($file,$filepath,$ecms=0){
	if(empty($file))
	{
		printerror("FileNotExist","history.go(-1)");
    }
	if(!file_exists($filepath))
	{
		printerror("FileNotExist","");
	}
	$filesize=@filesize($filepath);
	//下载
	Header("Content-type: application/octet-stream");
	Header("Accept-Ranges: bytes");
	Header("Accept-Length: ".$filesize);
	Header("Content-Disposition: attachment; filename=".$file);
	echo ReadFiletext($filepath);
	if($ecms==1)
	{
		DelFiletext($filepath);
	}
}

//去除adds
function ClearAddsData($data){
	$magic_quotes_gpc=get_magic_quotes_gpc();
	if($magic_quotes_gpc)
	{
		$data=stripSlashes($data);
	}
	return $data;
}

//增加adds
function AddAddsData($data){
	$magic_quotes_gpc=get_magic_quotes_gpc();
	if(!$magic_quotes_gpc)
	{
		$data=addslashes($data);
	}
	return $data;
}

//导入标签
function LoadInBq($add,$file,$file_name,$file_type,$file_size,$userid,$username){
	global $empire,$dbtbpre;
	//验证权限
    CheckLevel($userid,$username,$classid,"bq");
	$classid=(int)$add['classid'];
	if(!$file_name||!$file_size)
	{
		printerror("EmptyLoadInBqFile","history.go(-1)");
	}
	//扩展名
	$filetype=GetFiletype($file_name);
	if($filetype!=".bq")
	{
		printerror("LoadInBqMustBq","history.go(-1)");
	}
	$field="<!--#empirecms.bq-phome.net#--!>";
	$path="data/uploadbq".time().".bq";
	//上传文件
	$cp=@move_uploaded_file($file,$path);
	DoChmodFile($path);
	$data=ReadFiletext($path);
	DelFiletext($path);
	$r=explode($field,$data);
	$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsbq where bq='$r[3]' or funname='$r[2]' limit 1");
	if($num)
	{
		printerror("ReLoadInBq","history.go(-1)");
	}
	$sql=$empire->query("insert into {$dbtbpre}enewsbq(bqname,bqsay,funname,bq,issys,bqgs,isclose,classid) values('".addslashes($r[0])."','".addslashes($r[1])."','".addslashes($r[2])."','".addslashes($r[3])."',0,'".addslashes($r[4])."',0,$classid);");
	$bqid=$empire->lastid();
	//操作日志
	insert_dolog("bqid=".$bqid."<br>bqname=".$r[0]);
	return $r;
}

//批量替换地址权限
function RepDownLevel($add,$userid,$username){
	global $empire,$public_r,$class_r,$fun_r,$dbtbpre;
	//验证权限
	CheckLevel($userid,$username,$classid,"repdownpath");
	$tbname=RepPostVar($add['tbname']);
	if(!$tbname||!($add[downpath]||$add[onlinepath])||!($add[dogroup]||$add[dofen]||$add[doqz]||$add[dopath]||$add[doname]))
	{printerror("EmptyRepDownLevel","history.go(-1)");}
	$start=(int)$add['start'];
	//转换变量
	if(empty($add[oldgroupid]))
	{
		$add[oldgroupid]=0;
	}
	if(empty($add[newgroupid]))
	{
		$add[newgroupid]=0;
	}
	if(empty($add[oldfen]))
	{
		$add[oldfen]=0;
	}
	if(empty($add[newfen]))
	{
		$add[newfen]=0;
	}
	if(empty($add[oldqz]))
	{
		$add[oldqz]=0;
	}
	if(empty($add[newqz]))
	{
		$add[newqz]=0;
	}
	//字段
	$field="id";
	if($add['downpath'])
	{
		$field.=",downpath";
		$dh=",";
	}
	if($add['onlinepath'])
	{
		$field.=",onlinepath";
	}
	$wheresql="";
	//栏目
	$classid=(int)$add['classid'];
	if($classid)
	{
		if(empty($class_r[$classid][islast]))//中级栏目
		{
			$where=ReturnClass($class_r[$classid][sonclass]);
		}
		else//终极栏目
		{
			$where="classid='$classid'";
		}
		$wheresql.=" and (".$where.")";
	}
	//附加sql语句
	$query=$add['query'];
	if($query)
	{
		//取除adds
		$query=ClearAddsData($query);
		$wheresql.=" and (".$query.")";
	}
	$update="";
	$b=0;
	$sql=$empire->query("select ".$field." from {$dbtbpre}ecms_".$tbname." where id>$start".$wheresql." order by id limit ".$public_r['dorepdlevelnum']);
	while($r=$empire->fetch($sql))
	{
		$b=1;
		$newstart=$r[id];
		$update='';
		//下载地址
		$newdownpath="";
		if($add[downpath])
		{
			$newdownpath=RepDownLevelStrip($r[downpath],$add);
			$update="downpath='".addslashes($newdownpath)."'";
		}
		//在线地址
		$newonlinepath="";
		if($add[onlinepath])
		{
			$newonlinepath=RepDownLevelStrip($r[onlinepath],$add);
			$update.=$dh."onlinepath='".addslashes($newonlinepath)."'";
		}
		$usql=$empire->query("update {$dbtbpre}ecms_".$tbname." set ".$update." where id=$r[id]");
	}
	//替换完毕
	if(empty($b))
	{
		//操作日志
	    insert_dolog("tbname=$tbname<br>downpath=$add[downpath]<br>onlinepath=$add[onlinepath]");
		printerror("RepDownLevelSuccess","DownSys/RepDownLevel.php");
	}
	EchoRepDownLevelForm($add,$newstart);
}

//替换权限处理函数
function RepDownLevelStrip($downpath,$add){
	if(empty($downpath))
	{
		return "";
	}
	$add[oldpath]=ClearAddsData($add[oldpath]);
	$add[newpath]=ClearAddsData($add[newpath]);
	$add[oldname]=ClearAddsData($add[oldname]);
	$add[newname]=ClearAddsData($add[newname]);
	$f_exp="::::::";
	$r_exp="\r\n";
	$newdownpath="";
	$downpath=stripSlashes($downpath);
	$down_rr=explode($r_exp,$downpath);
	$count=count($down_rr);
	for($i=0;$i<$count;$i++)
	{
		$down_fr=explode($f_exp,$down_rr[$i]);
		//权限替换
		$d_groupid=(int)$down_fr[2];
		if($add[dogroup])
		{
			if($add[oldgroupid]=="no")//不设置
			{
				$d_groupid=$add[newgroupid];
			}
			else//设置
			{
				if($d_groupid==$add[oldgroupid])
				{
					$d_groupid=$add[newgroupid];
				}
			}
		}
		//点数转换
		$d_fen=(int)$down_fr[3];
		if($add[dofen])
		{
			if($add[oldfen]=="no")//不设置
			{
				$d_fen=$add[newfen];
			}
			else//设置
			{
				if($d_fen==$add[oldfen])
				{
					$d_fen=$add[newfen];
				}
			}
		}
		//前缀转换
		$d_qz=(int)$down_fr[4];
		if($add[doqz])
		{
			if($add[oldqz]=="no")//不设置
			{
				$d_qz=$add['newqz'];
			}
			else//设置
			{
				if($d_qz==$add[oldqz])
				{
					$d_qz=$add[newqz];
				}
			}
		}
		//地址替换
		$d_path=$down_fr[1];
		if($add[dopath]&&$add[oldpath])
		{
			$d_path=str_replace($add[oldpath],$add[newpath],$down_fr[1]);
		}
		//名称替换
		$d_name=$down_fr[0];
		if($add[doname]&&$add[oldname])
		{
			$d_name=str_replace($add[oldname],$add[newname],$down_fr[0]);
		}
		//组合
		$newdownpath.=$d_name.$f_exp.$d_path.$f_exp.$d_groupid.$f_exp.$d_fen.$f_exp.$d_qz.$r_exp;
	}
	//去掉最后的字符
	$newdownpath=substr($newdownpath,0,strlen($newdownpath)-2);
	return $newdownpath;
}

//输出批量替换下载权限表单
function EchoRepDownLevelForm($add,$newstart){
	global $fun_r;
	?>
	<?=$fun_r['RepOneDLeveSuccess']?>(ID:<font color=red><b><?=$newstart?></b></font>)
	<form name="RepDownLevelForm" method="post" action="enews.php">
		<input type=hidden name="enews" value="RepDownLevel">
		<input type=hidden name="start" value="<?=$newstart?>">
		<input type=hidden name="tbname" value="<?=$add['tbname']?>">
		<input type=hidden name="classid" value="<?=$add['classid']?>">
		<input type=hidden name="downpath" value="<?=$add['downpath']?>">
		<input type=hidden name="onlinepath" value="<?=$add['onlinepath']?>">
		<input type=hidden name="dogroup" value="<?=$add['dogroup']?>">
		<input type=hidden name="oldgroupid" value="<?=$add['oldgroupid']?>">
		<input type=hidden name="newgroupid" value="<?=$add['newgroupid']?>">
		<input type=hidden name="dofen" value="<?=$add['dofen']?>">
		<input type=hidden name="oldfen" value="<?=$add['oldfen']?>">
		<input type=hidden name="newfen" value="<?=$add['newfen']?>">
		<input type=hidden name="doqz" value="<?=$add['doqz']?>">
		<input type=hidden name="oldqz" value="<?=$add['oldqz']?>">
		<input type=hidden name="newqz" value="<?=$add['newqz']?>">
		<input type=hidden name="dopath" value="<?=$add['dopath']?>">
		<input type=hidden name="oldpath" value="<?=htmlspecialchars(ClearAddsData($add['oldpath']))?>">
		<input type=hidden name="newpath" value="<?=htmlspecialchars(ClearAddsData($add['newpath']))?>">
		<input type=hidden name="doname" value="<?=$add['doname']?>">
		<input type=hidden name="oldname" value="<?=htmlspecialchars(ClearAddsData($add['oldname']))?>">
		<input type=hidden name="newname" value="<?=htmlspecialchars(ClearAddsData($add['newname']))?>">
		<input type=hidden name="query" value="<?=htmlspecialchars(ClearAddsData($add['query']))?>">
	</form>
	<script>
	document.RepDownLevelForm.submit();
	</script>
	<?
	exit();
}

//生成自定义js
function ReUserjs($jsr,$addpath){
	global $empire;
	//取得js模板
	$jstemptext=GetTheJstemp($jsr[jstempid]);
	$temp_r=explode("[!--empirenews.listtemp--]",$jstemptext[temptext]);
	$query=stripSlashes($jsr[jssql]);
	$query=RepSqlTbpre($query);
	$sql=$empire->query($query);
	while($r=$empire->fetch($sql))
	{
		$newstime=format_datetime($r[newstime],$jstemptext[showdate]);
		$r[title]=str_replace("\r\n","",$r[title]);
		$oldtitle=$r[title];
		$title=sub(stripSlashes($r[title]),0,$jsr[substr],false);
		$title=RepJsTemp($temp_r[1],$r,$title,$newstime,$oldtitle);
		$allnew.=$title;
	}
	$allnew="document.write(\"".$temp_r[0].addslashes($allnew).$temp_r[2]."\");";
	WriteFiletext_n($addpath.$jsr['jsfilename'],$allnew);
}

//批量刷新自定义JS
function ReUserjsAll($start=0,$from,$userid,$username){
	global $empire,$public_r,$fun_r,$dbtbpre;
	$start=(int)$start;
	$b=0;
	$sql=$empire->query("select jsid,jsname,jssql,jstempid,jsfilename,substr from {$dbtbpre}enewsuserjs where jsid>$start order by jsid limit ".$public_r['reuserjsnum']);
	while($r=$empire->fetch($sql))
	{
		$b=1;
		$newstart=$r[jsid];
		ReUserjs($r,"");
	}
	//完毕
	if(empty($b))
	{
		//操作日志
	    insert_dolog("");
		printerror("ReUserjsAllSuccess",$from);
	}
	echo $fun_r['OneReUserjsSuccess']."(ID:<font color=red><b>".$newstart."</b></font>)<script>self.location.href='enews.php?enews=ReUserjsAll&start=$newstart&from=$from';</script>";
	exit();
}

//生成自定义信息列表
function ReUserlist($listr,$addpath){
	$listr['addpath']=$addpath;
	ListHtml($classid,$field,4,$listr);
}

//批量刷新自定义信息列表
function ReUserlistAll($start=0,$from,$userid,$username){
	global $empire,$public_r,$fun_r,$dbtbpre;
	$start=(int)$start;
	$b=0;
	$sql=$empire->query("select listid,pagetitle,filepath,filetype,totalsql,listsql,maxnum,lencord,listtempid from {$dbtbpre}enewsuserlist where listid>$start order by listid limit ".$public_r['reuserlistnum']);
	while($r=$empire->fetch($sql))
	{
		$b=1;
		$newstart=$r[listid];
		ReUserlist($r,"");
	}
	//完毕
	if(empty($b))
	{
		//操作日志
	    insert_dolog("");
		printerror("ReUserlistAllSuccess",$from);
	}
	echo $fun_r['OneReUserlistSuccess']."(ID:<font color=red><b>".$newstart."</b></font>)<script>self.location.href='enews.php?enews=ReUserlistAll&start=$newstart&from=$from';</script>";
	exit();
}

//取得缓存文件内容
function GetFcfiletext($file){
	$str1="document.write(\"";
	$str2="\");";
	$text=ReadFiletext($file);
	$text=stripSlashes(str_replace($str2,"",str_replace($str1,"",$text)));
	return $text;
}

//批量生成动态页面
function ReDtPage($userid,$username){
	//操作权限
	CheckLevel($userid,$username,$classid,"changedata");
	GetSearchResult();//评论列表模板
	ReCptemp();//控制面板模板
	GetSearch();//三搜索表单模板
	GetPrintPage();//打印模板
	ReGbooktemp();//留言板模板
	ReLoginIframe();//登陆状态模板
	//操作日志
	insert_dolog("");
	printerror("ReDtPageSuccess","history.go(-1)");
}

//复制表
function CopyEcmsTb($otb,$tb){
	global $empire;
	$usql=$empire->query("SET SQL_QUOTE_SHOW_CREATE=1;");//设置引号
	$r=$empire->fetch1("SHOW CREATE TABLE `$otb`;");//数据表结构
	$create=str_replace("\"","\\\"",$r[1]);
	$create=str_replace($otb,$tb,$create);
	$empire->query($create);
}

//建立数据表
function SetCreateTable($sql,$dbcharset) {
	global $phome_use_dbver;
	$type=strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU", "\\2", $sql));
	$type = in_array($type, array('MYISAM', 'HEAP')) ? $type : 'MYISAM';
	return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU", "\\1", $sql).
		($phome_use_dbver>='4.1'&&$dbcharset ? " ENGINE=$type DEFAULT CHARSET=$dbcharset" : " TYPE=$type");
}

//归档信息
function InfoToDoc($add,$userid,$username){
	global $empire,$dbtbpre;
	$time=time();
	if($add['ecmsdoc']==1)//多栏目
	{
		//操作权限
		CheckLevel($userid,$username,$classid,"class");
		$classid=$add['reclassid'];
		$count=count($classid);
		if($count==0)
		{
			printerror("EmptyDocClass","");
		}
		for($i=0;$i<$count;$i++)
		{
			$cr=$empire->fetch1("select tbname,doctime from {$dbtbpre}enewsclass where classid='".$classid[$i]."' and islast=1");
			if($cr['tbname']&&$cr['doctime'])
			{
				$doctime=$cr['doctime']*24*3600;
				$where="classid='$classid[$i]' and ".$time."-truetime>".$doctime;
				DoDocInfo($cr['tbname'],$where);
			}
		}
		$log="tbname=".$cr['tbname'];
	}
	elseif($add['ecmsdoc']==2)//多信息归档
	{
		$classid=(int)$add['classid'];
		//操作权限
		CheckLevel($userid,$username,$classid,"news");
		$id=$add['id'];
		$count=count($id);
		if($count==0)
		{
			printerror("EmptyDocInfo","");
		}
		$cr=$empire->fetch1("select tbname from {$dbtbpre}enewsclass where classid=$classid");
		if(empty($cr['tbname']))
		{
			printerror("EmptyDocInfo","");
		}
		for($i=0;$i<$count;$i++)
		{
			$dh=",";
			if($i==0)
			{
				$dh="";
			}
			$ids.=$dh.$id[$i];
		}
		$where="id in (".$ids.")";
		DoDocInfo($cr['tbname'],$where,$add['doing']);
		$log="tbname=".$cr['tbname']."<br>doing=$add[doing]";
	}
	elseif($add['ecmsdoc']==3)//批量归档
	{
		//操作权限
		CheckLevel($userid,$username,$classid,"infodoc");
		$tbname=RepPostVar($add['tbname']);
		if(empty($tbname))
		{
			printerror("EmptyDocTb","");
		}
		$classid=$add['classid'];
		$count=count($classid);
		if($count==0)
		{
			printerror("EmptyDocInfo","");
		}
		if($add['retype']==0)//按天数归档
		{
			if($add['doing']==1)
			{
				$doctime=(int)$add['doctime1'];
				$dx="<";
			}
			else
			{
				$doctime=(int)$add['doctime'];
				$dx=">";
			}
			if(!$doctime)
			{
				printerror("EmptyDoctime","");
			}
			$doctime=$doctime*24*3600;
			$where=$time."-truetime".$dx.$doctime;
			$log="doctime=$doctime";
		}
		elseif($add['retype']==1)//按时间归档
		{
			$startday=RepPostVar($add['startday']);
			$endday=RepPostVar($add['endday']);
			if(!$endday)
			{
				printerror("EmptyDocDay","");
			}
			if($startday)
			{
				$where="truetime>=".to_time($startday." 00:00:00")." and ";
			}
			$where.="truetime<=".to_time($endday." 23:59:59");
			$log="startday=$startday<br>endday=$endday";
		}
		else//按ID归档
		{
			$startid=(int)$add['startid'];
			$endid=(int)$add['endid'];
			if(!$endid)
			{
				printerror("EmptyDocId","");
			}
			if($startid)
			{
				$where="id>=".$startid." and ";
			}
			$where.="id<=".$endid;
			$log="startid=$startid<br>endid=$endid";
		}
		//栏目
		for($i=0;$i<$count;$i++)
		{
			$dh=",";
			if($i==0)
			{
				$dh="";
			}
			$ids.=$dh.$classid[$i];
		}
		$where.=" and classid in (".$ids.")";
		DoDocInfo($tbname,$where,$add['doing']);
		$log.="<br>doing=$add[doing]";
	}
	else
	{
		printerror("ErrorUrl","");
	}
	$add['docfrom']=urldecode($add['docfrom']);
	//操作日志
	insert_dolog($log);
	printerror("InfoToDocSuccess",$add['docfrom']);
}

//处理归档
function DoDocInfo($tb,$where,$ecms=0){
	global $empire,$dbtbpre;
	if($ecms==1)//还原
	{
		$empire->query("insert into ".$dbtbpre."ecms_".$tb." select * from ".$dbtbpre."ecms_".$tb."_doc where ".$where." order by id");
		$empire->query("delete from ".$dbtbpre."ecms_".$tb."_doc where ".$where);
	}
	else//归档
	{
		$empire->query("insert into ".$dbtbpre."ecms_".$tb."_doc select * from ".$dbtbpre."ecms_".$tb." where ".$where." order by id");
		$empire->query("delete from ".$dbtbpre."ecms_".$tb." where ".$where);
	}
}

//验证模板组是否存在
function CheckTempGroup($gid){
	global $empire,$dbtbpre;
	if(empty($gid))
	{
		$gid=GetDoTempGid();
	}
	$r=$empire->fetch1("select gid,gname from {$dbtbpre}enewstempgroup where gid='$gid'");
	if(empty($r['gid']))
	{
		printerror("ErrorUrl","");
	}
	return $r['gname'];
}

//导入系统模型
function LoadInMod($add,$file,$file_name,$file_type,$file_size,$userid,$username){
	global $empire,$dbtbpre,$phome_db_dbchar;
	//验证权限
	CheckLevel($userid,$username,$classid,"table");

	$tbname=RepPostVar(trim($add['tbname']));
	if(!$file_name||!$file_size||!$tbname)
	{
		printerror("EmptyLoadInMod","");
	}
	//扩展名
	$filetype=GetFiletype($file_name);
	if($filetype!=".mod")
	{
		printerror("LoadInModMustmod","");
	}
	//表名是否已存在
	$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewstable where tbname='$tbname' limit 1");
	if($num)
	{
		printerror("HaveLoadInTb","");
	}
	//上传文件
	$path="db/mod/uploadm".time().".php";
	$cp=@move_uploaded_file($file,$path);
	if(!$cp)
	{
		printerror("EmptyLoadInMod","");
	}
	DoChmodFile($path);
	@include($path);
	//公共变量
	TogSaveTxtF();
	//生成模型表单文件
	$modr=$empire->fetch1("select mtemp,qmtemp,cj from {$dbtbpre}enewsmod where mid=$mid");
	ChangeMForm($mid,$tid,$modr[mtemp]);//更新表单
	ChangeQmForm($mid,$tid,$modr[qmtemp]);//更新前台表单
	ChangeMCj($mid,$tid,$modr[cj]);//采集表单
	//删除文件
	DelFiletext($path);
	//操作日志
	insert_dolog("tid=$tid&tb=$tbname<br>mid=$mid");
	printerror("LoadInModSuccess","db/ListTable.php");
}
?>